Loading django/db/models/fields/related.py +10 −1 Original line number Diff line number Diff line Loading @@ -989,7 +989,16 @@ class ForeignObject(RelatedField): @staticmethod def get_instance_value_for_fields(instance, fields): return tuple([getattr(instance, field.attname) for field in fields]) ret = [] for field in fields: # Gotcha: in some cases (like fixture loading) a model can have # different values in parent_ptr_id and parent's id. So, use # instance.pk (that is, parent_ptr_id) when asked for instance.id. if field.primary_key: ret.append(instance.pk) else: ret.append(getattr(instance, field.attname)) return tuple(ret) def get_attname_column(self): attname, column = super(ForeignObject, self).get_attname_column() Loading tests/fixtures_regress/fixtures/special-article.json 0 → 100644 +10 −0 Original line number Diff line number Diff line [ { "pk": 1, "model": "fixtures_regress.specialarticle", "fields": { "title": "Article Title 1", "channels": [] } } ] tests/fixtures_regress/models.py +5 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,11 @@ class Article(models.Model): ordering = ('id',) # Subclass of a model with a ManyToManyField for test_ticket_20820 class SpecialArticle(Article): pass # Models to regression test #11428 @python_2_unicode_compatible class Widget(models.Model): Loading tests/fixtures_regress/tests.py +11 −0 Original line number Diff line number Diff line Loading @@ -444,6 +444,17 @@ class TestFixtures(TestCase): self.assertTrue("No fixture 'this_fixture_doesnt_exist' in" in force_text(stdout_output.getvalue())) def test_ticket_20820(self): """ Regression for ticket #20820 -- loaddata on a model that inherits from a model with a M2M shouldn't blow up. """ management.call_command( 'loaddata', 'special-article.json', verbosity=0, ) class NaturalKeyFixtureTests(TestCase): Loading Loading
django/db/models/fields/related.py +10 −1 Original line number Diff line number Diff line Loading @@ -989,7 +989,16 @@ class ForeignObject(RelatedField): @staticmethod def get_instance_value_for_fields(instance, fields): return tuple([getattr(instance, field.attname) for field in fields]) ret = [] for field in fields: # Gotcha: in some cases (like fixture loading) a model can have # different values in parent_ptr_id and parent's id. So, use # instance.pk (that is, parent_ptr_id) when asked for instance.id. if field.primary_key: ret.append(instance.pk) else: ret.append(getattr(instance, field.attname)) return tuple(ret) def get_attname_column(self): attname, column = super(ForeignObject, self).get_attname_column() Loading
tests/fixtures_regress/fixtures/special-article.json 0 → 100644 +10 −0 Original line number Diff line number Diff line [ { "pk": 1, "model": "fixtures_regress.specialarticle", "fields": { "title": "Article Title 1", "channels": [] } } ]
tests/fixtures_regress/models.py +5 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,11 @@ class Article(models.Model): ordering = ('id',) # Subclass of a model with a ManyToManyField for test_ticket_20820 class SpecialArticle(Article): pass # Models to regression test #11428 @python_2_unicode_compatible class Widget(models.Model): Loading
tests/fixtures_regress/tests.py +11 −0 Original line number Diff line number Diff line Loading @@ -444,6 +444,17 @@ class TestFixtures(TestCase): self.assertTrue("No fixture 'this_fixture_doesnt_exist' in" in force_text(stdout_output.getvalue())) def test_ticket_20820(self): """ Regression for ticket #20820 -- loaddata on a model that inherits from a model with a M2M shouldn't blow up. """ management.call_command( 'loaddata', 'special-article.json', verbosity=0, ) class NaturalKeyFixtureTests(TestCase): Loading