Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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 Tim Graham)

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 Tim Graham, 9 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted

comment:2 by Simon Charette, 9 years ago

Needs documentation: set

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 use super().__init__ on Python 3.

comment:3 by Anshuman Aggarwal, 9 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.

Last edited 9 years ago by Anshuman Aggarwal (previous) (diff)

comment:4 by Tim Graham, 9 years ago

Component: contrib.adminDocumentation
Easy pickings: set
Needs documentation: unset
Summary: NameError: global name XXXXXAdmin is not defined when using admin register decorator with an __init__ super callDocument that you cannot use @admin.register() with an __init__() super call that references the class name
Type: BugCleanup/optimization

comment:5 by Tim Graham, 9 years ago

Has patch: set

comment:6 by Simon Charette, 9 years ago

Triage Stage: AcceptedReady for checkin

LGTM

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 4cd2bdae:

Fixed #24323 -- Documented @admin.register can't be used with super(XXXAdmin in init().

comment:8 by Tim Graham <timograham@…>, 9 years ago

In 5ebf6fd8:

[1.8.x] Fixed #24323 -- Documented @admin.register can't be used with super(XXXAdmin in init().

Backport of 4cd2bdae07ac5561fdae0eede58c68df4dfcc780 from master

comment:9 by Tim Graham <timograham@…>, 9 years ago

In 76aa4cc:

[1.9.x] Fixed #24323 -- Documented @admin.register can't be used with super(XXXAdmin in init().

Backport of 4cd2bdae07ac5561fdae0eede58c68df4dfcc780 from master

Note: See TracTickets for help on using tickets.
Back to Top