pythondjangodjango-adminmezzaninecartridge

Mezzanine custom field adding to admin


I am writing a piece of software and have added an extra field using mezzanines model injection ability's the field is there and can be seen in the database but following the method shown in the docs on this page mezzanine model customisation I cannot get it to show up in my admin page bellow is the code I have written that I believe should work to de-register and then re-register with the new field added to the admin. I am unsure if this code is even running it is in the root of my project as I believe that is where it should be and named admin.py as I believe it should be and have used that file in other projects.

from copy import deepcopy
from django.contrib import admin
from catridge.shop.admin import ProductAdmin
from catridge.shop.models import Product

product_fieldsets = deepcopy(ProductAdmin.fieldsets)
product_fieldsets[0][1]["fields"].insert(-2, "download_file")

class MyProductAdmin(ProductAdmin):
    fieldsets = product_fieldsets

admin.site.unregister(Product)
admin.site.register(Product, MyProductAdmin)

Does anyone have any idea as to how this might work I am a bit stumped currently but this is mainly a mezzanine function.


Solution

  • The admin.py file needs to go inside one of your INSTALLED_APPS directories.