#32975: ModelAdmin for proxy model with InlineModelAdmin for proxy superclass
reference results in admin.E202
-------------------------------------+-------------------------------------
Reporter: Lucas Weyne | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution:
Keywords: proxy, | Triage Stage:
InlineModelAdmin, E202 | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Lucas Weyne:
Old description:
> This is similar to #30273, but in this case, the `InlineModelAdmin.model`
> is a model with references to a proxy superclass
>
> Assume the following Django models:
>
> {{{#!python
>
> class Reporter(models.Model):
> name = models.CharField(max_length=50)
>
> class Journalist(Reporter):
>
> class Meta:
> proxy = True
>
> class SpecialJournalist(Journalist):
>
> class Meta:
> proxy = True
>
> class Article(models.Model):
> journalist = models.ForeignKey(Journalist, on_delete=models.CASCADE)
> }}}
>
> Register model admins as follows (exemplary):
>
> {{{#!python
>
> class ArticleInline(admin.TabularInline):
> model = Article
> fk_name = 'reporter'
>
> @admin.register(SpecialJournalist)
> class SpecialJournalistAdmin(admin.ModelAdmin):
> inlines = [ArticleInline]
>
> }}}
>
> This will result in the following error:
> {{{
> <class 'ArticleInline'>: (admin.E202) fk_name 'journalist' is not a
> ForeignKey to 'SpecialJournalist'.
> }}}
>
> This problem occurs on this check this check:
> https://github.com/django/django/blob/3.1.13/django/forms/models.py#L1006
>
> A `ValueError` is raised because the result for
> `SpecialJournalist._meta.get_parent_list()` does not include
> `Journalist`:
>
> {{{#!python
> >>> SpecialJournalist._meta.get_parent_list()
> [<class 'Reporter'>]
> }}}
New description:
This is similar to #30273, but in this case, the `InlineModelAdmin.model`
is a model with references to a proxy superclass
Assume the following Django models:
{{{#!python
class Reporter(models.Model):
name = models.CharField(max_length=50)
class Journalist(Reporter):
class Meta:
proxy = True
class SpecialJournalist(Journalist):
class Meta:
proxy = True
class Article(models.Model):
journalist = models.ForeignKey(Journalist, on_delete=models.CASCADE)
}}}
Register model admins as follows (exemplary):
{{{#!python
class ArticleInline(admin.TabularInline):
model = Article
fk_name = 'reporter'
@admin.register(SpecialJournalist)
class SpecialJournalistAdmin(admin.ModelAdmin):
inlines = [ArticleInline]
}}}
This will result in the following error:
{{{
<class 'ArticleInline'>: (admin.E202) fk_name 'journalist' is not a
ForeignKey to 'SpecialJournalist'.
}}}
This problem occurs on this check this check:
https://github.com/django/django/blob/3.1.13/django/forms/models.py#L1006
A `ValueError` is raised because the result for
`SpecialJournalist._meta.get_parent_list()` does not include `Journalist`:
{{{
>>> SpecialJournalist._meta.get_parent_list()
[<class 'Reporter'>]
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32975#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.d713365b5c900d63bf4d9a4c54d40dc9%40djangoproject.com.