#24323 closed Cleanup/optimization (fixed)
Document that you cannot use @admin.register() with an __init__() super call that references the class name
Reported by: | Anshuman Aggarwal | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
When registering a django admin using the
@admin.register(XXXX) class XXXXAdmin(admin.ModelAdmin): def __init__(self, *args, **kwargs): super(XXXXAdmin, self).__init__(*args, **kwargs)
gives an exception:
NameError: global name XXXXXAdmin is not defined
Change History (9)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 10 years ago
Needs documentation: | set |
---|
comment:3 by , 10 years ago
Sounds like an acceptable solution for now (I can confirm it works). The Python3 super may be a reasonable solution in the very long term.
comment:4 by , 9 years ago
Component: | contrib.admin → Documentation |
---|---|
Easy pickings: | set |
Needs documentation: | unset |
Summary: | NameError: global name XXXXXAdmin is not defined when using admin register decorator with an __init__ super call → Document that you cannot use @admin.register() with an __init__() super call that references the class name |
Type: | Bug → Cleanup/optimization |
Note:
See TracTickets
for help on using tickets.
Because of the way model admin registration and class decoration works I doubt we'll be able to fix this in an elegant way.
I suggest we document to use
site.register
if you have to reference your model admin during its initialization phase or simply usesuper().__init__
on Python 3.