mirror of
https://github.com/django/django.git
synced 2025-03-13 10:50:55 +00:00
Fixed #34927 -- Fixed admin system check for inlines with foreign keys to proxy models.
Follow up to 0e8be73812a6e62d5a6b12a585d133b56bc2bf52.
This commit is contained in:
parent
36173cf29d
commit
65c283be16
1
AUTHORS
1
AUTHORS
@ -93,6 +93,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
ant9000@netwise.it
|
ant9000@netwise.it
|
||||||
Anthony Briggs <anthony.briggs@gmail.com>
|
Anthony Briggs <anthony.briggs@gmail.com>
|
||||||
Anthony Wright <ryow.college@gmail.com>
|
Anthony Wright <ryow.college@gmail.com>
|
||||||
|
Antoine Chéneau <antoine.cheneau@outlook.com>
|
||||||
Anton Samarchyan <desecho@gmail.com>
|
Anton Samarchyan <desecho@gmail.com>
|
||||||
Antoni Aloy
|
Antoni Aloy
|
||||||
Antonio Cavedoni <http://cavedoni.com/>
|
Antonio Cavedoni <http://cavedoni.com/>
|
||||||
|
@ -1211,6 +1211,7 @@ def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):
|
|||||||
if len(fks_to_parent) == 1:
|
if len(fks_to_parent) == 1:
|
||||||
fk = fks_to_parent[0]
|
fk = fks_to_parent[0]
|
||||||
parent_list = parent_model._meta.get_parent_list()
|
parent_list = parent_model._meta.get_parent_list()
|
||||||
|
parent_list.append(parent_model)
|
||||||
if (
|
if (
|
||||||
not isinstance(fk, ForeignKey)
|
not isinstance(fk, ForeignKey)
|
||||||
or (
|
or (
|
||||||
@ -1236,6 +1237,7 @@ def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):
|
|||||||
else:
|
else:
|
||||||
# Try to discover what the ForeignKey from model to parent_model is
|
# Try to discover what the ForeignKey from model to parent_model is
|
||||||
parent_list = parent_model._meta.get_parent_list()
|
parent_list = parent_model._meta.get_parent_list()
|
||||||
|
parent_list.append(parent_model)
|
||||||
fks_to_parent = [
|
fks_to_parent = [
|
||||||
f
|
f
|
||||||
for f in opts.fields
|
for f in opts.fields
|
||||||
|
@ -1268,6 +1268,45 @@ class FkNameCheckTests(CheckTestCase):
|
|||||||
|
|
||||||
self.assertIsValid(TestModelAdmin, ValidationTestModel)
|
self.assertIsValid(TestModelAdmin, ValidationTestModel)
|
||||||
|
|
||||||
|
def test_proxy_model(self):
|
||||||
|
class Reporter(Model):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ProxyJournalist(Reporter):
|
||||||
|
class Meta:
|
||||||
|
proxy = True
|
||||||
|
|
||||||
|
class Article(Model):
|
||||||
|
reporter = ForeignKey(ProxyJournalist, on_delete=CASCADE)
|
||||||
|
|
||||||
|
class ArticleInline(admin.TabularInline):
|
||||||
|
model = Article
|
||||||
|
|
||||||
|
class ReporterAdmin(admin.ModelAdmin):
|
||||||
|
inlines = [ArticleInline]
|
||||||
|
|
||||||
|
self.assertIsValid(ReporterAdmin, Reporter)
|
||||||
|
|
||||||
|
def test_proxy_model_fk_name(self):
|
||||||
|
class ReporterFkName(Model):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ProxyJournalistFkName(ReporterFkName):
|
||||||
|
class Meta:
|
||||||
|
proxy = True
|
||||||
|
|
||||||
|
class ArticleFkName(Model):
|
||||||
|
reporter = ForeignKey(ProxyJournalistFkName, on_delete=CASCADE)
|
||||||
|
|
||||||
|
class ArticleInline(admin.TabularInline):
|
||||||
|
model = ArticleFkName
|
||||||
|
fk_name = "reporter"
|
||||||
|
|
||||||
|
class ReporterAdmin(admin.ModelAdmin):
|
||||||
|
inlines = [ArticleInline]
|
||||||
|
|
||||||
|
self.assertIsValid(ReporterAdmin, ReporterFkName)
|
||||||
|
|
||||||
def test_proxy_model_parent(self):
|
def test_proxy_model_parent(self):
|
||||||
class Parent(Model):
|
class Parent(Model):
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user