diff --git a/polymorphic/tests/migrations/0002_blueheadduck_delete_inlinemodelbase_and_more.py b/polymorphic/tests/migrations/0002_blueheadduck_delete_inlinemodelbase_and_more.py new file mode 100644 index 00000000..64f86279 --- /dev/null +++ b/polymorphic/tests/migrations/0002_blueheadduck_delete_inlinemodelbase_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.2.15 on 2024-08-20 06:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('tests', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='BlueHeadDuck', + fields=[ + ('duck_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='tests.duck')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('tests.duck',), + ), + migrations.CreateModel( + name='PurpleHeadDuck', + fields=[ + ], + options={ + 'proxy': True, + 'indexes': [], + 'constraints': [], + }, + bases=('tests.blueheadduck',), + ), + ] diff --git a/polymorphic/tests/models.py b/polymorphic/tests/models.py index 76e1b626..d43bc33b 100644 --- a/polymorphic/tests/models.py +++ b/polymorphic/tests/models.py @@ -496,3 +496,28 @@ class SubclassSelectorProxyConcreteModel(SubclassSelectorProxyModel): class NonPolymorphicParent(PolymorphicModel, Group): test = models.CharField(max_length=22, default="test_non_polymorphic_parent") + + +# models for https://github.com/jazzband/django-polymorphic/issues/615 + + +class BlueHeadDuck(Duck): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # This wasn't run before the fix: + self.color = "blue" + + +class HomeDuck(models.Model): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.home = "Duckburg" + + class Meta: + abstract = True + + +# Not sure if this will be necessary... +class PurpleHeadDuck(HomeDuck, BlueHeadDuck): + class Meta: + proxy = True diff --git a/polymorphic/tests/test_query.py b/polymorphic/tests/test_query.py new file mode 100644 index 00000000..8d47b0d8 --- /dev/null +++ b/polymorphic/tests/test_query.py @@ -0,0 +1,12 @@ +from polymorphic.tests.models import Duck, PurpleHeadDuck + + +def test_transmogrify_with_init(db): + pur = PurpleHeadDuck.objects.create() + assert pur.color == "blue" + assert pur.home == "Duckburg" + + pur = Duck.objects.get(id=pur.id) + assert pur.color == "blue" + # issues/615 fixes following line: + assert pur.home == "Duckburg"