1👍
You are trying to register BookAdmin
before actually creating it. Just move admin.site.register(Book, BookAdmin)
after the class definition and it will work as expected.
class BookAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['publication_date']}),
('Date infomation', {'fields': ['publisher']}),
]
admin.site.register(Book, BookAdmin)
0👍
It looks like you are trying to register BookAdmin
before it’s definition. When the line admin.site.register(Book, BookAdmin)
runs, the class BookAdmin
hasn’t been defined yet.
Re-arrange the code slightly so you have:
class BookAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['publication_date']}),
('Date infomation', {'fields': ['publisher']}),
]
admin.site.register(Book, BookAdmin)
- PythonAnywhere credentials cannot access the Django Control Panel
- ◈ LoginRequired for the view 💈 Django 1.8
- Django Rest Framework, default serializer for foreign key field
Source:stackexchange.com