jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting

Home Page:https://django-polymorphic.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Other options are ignored by migration algorithm

ClundXIII opened this issue · comments

Lets take a model like this:

class Test(PolymorphicModel):
  created_date = models.DateTimeField(default=timezone.now)

  class Meta:
    ordering = ['-created_date']

With an initial migration:

        migrations.CreateModel(
            name='Test',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_date', models.DateTimeField(default=django.utils.timezone.now)),
                ('polymorphic_ctype', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_%(app_label)s.%(class)s_set+', to='contenttypes.contenttype')),
            ],
            options={
                'abstract': False,
                'base_manager_name': 'objects',
                'ordering': ['-created_date'],
            },
        ),

Note, that I merged the order and polymorphic options together. Unfortunately django fails to recognize the ordering option and will create this migrations when running makemigrations;

        migrations.AlterModelOptions(
            name='Test',
            options={'ordering': ['-created_date']},
        ),

This is not a big deal and an has an easy workaround just appending the options below. However my guess would be that there is some super() call missing inside the Polymorphic handling of CreateModel. So this might be a symptom of an issue that is deep down in the code.

Thanks for bringing this up. Please feel free to dive into the code and see if there is a potential fix!