﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24470	Serialization of base classes is not customizable for migrations	Rocky Meza	nobody	"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,"	New feature	new	Migrations	1.7	Normal				Accepted	0	0	0	0	0	0
