mirror of https://github.com/django/django.git
Fixed #34927 -- Fixed admin system check for inlines with foreign keys to proxy models.
Follow up to 0e8be73812
.
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
|
||||
Anthony Briggs <anthony.briggs@gmail.com>
|
||||
Anthony Wright <ryow.college@gmail.com>
|
||||
Antoine Chéneau <antoine.cheneau@outlook.com>
|
||||
Anton Samarchyan <desecho@gmail.com>
|
||||
Antoni Aloy
|
||||
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:
|
||||
fk = fks_to_parent[0]
|
||||
parent_list = parent_model._meta.get_parent_list()
|
||||
parent_list.append(parent_model)
|
||||
if (
|
||||
not isinstance(fk, ForeignKey)
|
||||
or (
|
||||
|
@ -1236,6 +1237,7 @@ def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):
|
|||
else:
|
||||
# Try to discover what the ForeignKey from model to parent_model is
|
||||
parent_list = parent_model._meta.get_parent_list()
|
||||
parent_list.append(parent_model)
|
||||
fks_to_parent = [
|
||||
f
|
||||
for f in opts.fields
|
||||
|
|
|
@ -1268,6 +1268,45 @@ class FkNameCheckTests(CheckTestCase):
|
|||
|
||||
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):
|
||||
class Parent(Model):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue