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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34927>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:1>
Comment (by Asfand Yar Khan):
Was able to reproduce this on my end.
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:3>
* component: Database layer (models, ORM) => contrib.admin
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:4>
* owner: nobody => chenow
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:5>
* has_patch: 0 => 1
Comment:
Made a PR here: https://github.com/django/django/pull/17434
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:6>
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:7>
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"65c283be163212f5679b5edbd6a24c88b3af04ce" 65c283b]:
{{{
#!CommitTicketReference repository=""
revision="65c283be163212f5679b5edbd6a24c88b3af04ce"
Fixed #34927 -- Fixed admin system check for inlines with foreign keys to
proxy models.
Follow up to 0e8be73812a6e62d5a6b12a585d133b56bc2bf52.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34927#comment:9>