#34927 closed Bug (fixed)

ModelAdmin for model with InlineModelAdmin for proxy class reference results in admin.E202

Reported by: Quinten Kock Owned by: Antoine Cheneau
Component: contrib.admin Version: 4.2
Severity: Normal Keywords: proxy, InlineModelAdmin, E202
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is similar to #30273 and #32975. A class references a proxy model, and we define an inline for the proxied model. This fails with admin.E202 because Django does not recognize that the FK to the proxy model is the same as an FK to the proxied model.

Assume models as follows:

class Reporter(models.Model):
    name = models.CharField(max_length=50)

class Journalist(Reporter):
    class Meta:
        proxy = True

class Article(models.Model):
    reporter = models.ForeignKey(Journalist, on_delete=models.CASCADE)

and an admin as follows:

class ArticleInline(admin.TabularInline):
    model = Article
    fk_name = 'reporter'

@admin.register(Reporter)
class ReporterAdmin(admin.ModelAdmin):
    inlines = [ArticleInline]

This will result in <class 'testapp.admin.ArticleInline'>: (admin.E202) fk_name 'reporter' is not a ForeignKey to 'testapp.Reporter'.

The problem seems to be that the parent list does not include the model itself, and as such Django does not recognize the equality here.

Change History (9)

comment:1 by Asfand Yar Khan, 14 months ago

Component: UncategorizedDatabase layer (models, ORM)

comment:2 by Asfand Yar Khan, 14 months ago

Was able to reproduce this on my end.

comment:3 by Asfand Yar Khan, 14 months ago

Triage Stage: UnreviewedAccepted

comment:4 by Mariusz Felisiak, 14 months ago

Component: Database layer (models, ORM)contrib.admin

comment:5 by Antoine Cheneau, 14 months ago

Owner: changed from nobody to Antoine Cheneau
Status: newassigned

comment:6 by Antoine Cheneau, 14 months ago

Has patch: set
Last edited 14 months ago by Antoine Cheneau (previous) (diff)

comment:7 by Mariusz Felisiak, 14 months ago

Needs tests: set
Patch needs improvement: set

comment:8 by Mariusz Felisiak, 14 months ago

Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

Resolution: fixed
Status: assignedclosed

In 65c283b:

Fixed #34927 -- Fixed admin system check for inlines with foreign keys to proxy models.

Follow up to 0e8be73812a6e62d5a6b12a585d133b56bc2bf52.

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