Opened 9 years ago

Closed 9 years ago

#24867 closed Bug (invalid)

admin.E202 seems to include superclass references?

Reported by: TorstenRottmann Owned by: nobody
Component: contrib.admin Version: 1.7
Severity: Normal Keywords: admin.E202
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have this three models defined:

class Act(models.Model):
    ....

class Form(Act):
    ...

class Diagnosis(Act):
    form = models.ForeignKey(Form)

...and this admin.py:

class DiagnosisInline(admin.TabularInline):
    model = Diagnosis
    ...

class FormAdmin(admin.ModelAdmin):
    ....
    inlines = [DiagnosisInline]

admin.site.register(Form, FormAdmin)

This triggers 'admin.E202':

<class 'nm.admin.DiagnosisInline'>: (admin.E202) 'nm.Diagnosis' has more than one ForeignKey to 'nm.Form'

Without looking into the source for this system check, I guess, that it counts all possible references, that lead to the admin class, the inline is included in.

And it counts two, from which one is right (Form) and one is wrong (Act), because it's already it's own superclass reference.

Am I right?

Change History (4)

comment:1 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

There's no need to have the foreign key on Diagnosis as that model has an automatically created OneToOneField to Form because your models use multi-table inheritance.

comment:2 by TorstenRottmann, 9 years ago

Well, that doesn't work. The inlines should be the Diagnosis, that point to a Form – and I simply can't manage that to work.
How is that done?

comment:3 by TorstenRottmann, 9 years ago

Resolution: invalid
Status: closednew

comment:4 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

Maybe what you meant to do is make Act an abstract base model. In that case, your original code should work fine.

For future reference, "is it a bug" type questions should be directed to our support channels at TicketClosingReasons/UseSupportChannels. Thanks!

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