Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django dumpdata of multi-table inherited objects

I am trying to ./manage.py dumpdata --natural-foreign --natural-primary my classes, which are:

class SuperClassManager(Manager):
    def get_by_natural_key(self, identifier):
        return self.get(identifier=identifier)

class SuperClass(Model):
    objects = SuperClassManager()

    identifier = CharField(max_length=31, unique=True)

    def natural_key(self):
        return (self.identifier, )

class Class(SuperClass):
    pass

But the dumped data is:

[
{
    "model": "app.superclass",
    "fields": {
        "identifier": "identifier"
    }
},
{
    "model": "app.class",
    "fields": {}
}
]

There's no way to relate the Class instance to the SuperClass instance in this case. What am I missing? Why isn't the superclass_ptr existent in Class (which points to SuperClass) being serialized so it is possible to relate the instances?

Problem being: I have more than one subclass to my superclass and many instances of each subclass. So I need this relation to happen so my fixtures will make sense.

like image 996
jpmelos Avatar asked Oct 30 '22 20:10

jpmelos


1 Answers

This is actually a bug, and the patch is under construction: https://github.com/django/django/pull/7231. So, no answer appropriate for this question, except wait for the patch.

like image 151
jpmelos Avatar answered Dec 14 '22 12:12

jpmelos