#24470: Serialization of base classes is not customizable for migrations -------------------------------+-------------------- Reporter: rockymeza | Owner: nobody Type: Uncategorized | Status: new Component: Migrations | Version: 1.7 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- I have a base class that is created by a class factory for one of my models. You can see an example [https://github.com/fusionbox/django- widgy/blob/master/widgy/models/mixins.py#L97-L117 here], but basically it works like this:
{{{#!python def CreateBaseClass(arg): class cls(object): def get_arg(self): return arg return cls class MyModel(CreateBaseClass('foo'), models.Model): # ... }}} When I run makemigrations, it serializes the base classes to something like this: {{{#!python migrations.CreateModel( name='MyModel', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ], options={}, bases=(myapp.models.cls, models.Model), ), }}} But this errors because myapp.models.cls doesn't exist. I think that Django should allow the base classes to customize their serialization so that the migration would end up something like this: {{{#!python bases=(myapp.models.CreateBaseClass('foo'), models.Model), }}} This could be done through a classmethod called deconstruct_class, and it would be used like this: {{{#!python def CreateBaseClass(arg): class cls(object): @classmethod def deconstruct_class(cls): return 'myapp.models.CreateBaseClass', (arg,), {} # ... return cls }}} Here are some related tickets: #23950, #22951 Thanks, -- Ticket URL: <https://code.djangoproject.com/ticket/24470> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.0b1ebebf8248e263e6a9299dffcf5f06%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.