Hi João,

It seems like this is an already reported bug[1] with an existing stale 
PR[2]
you might want to work on.

Cheers,
Simon

[1] https://code.djangoproject.com/ticket/24607
[2] https://github.com/django/django/pull/4473

Le samedi 10 septembre 2016 10:32:01 UTC-4, João Sampaio a écrit :
>
> Hello!
>
> I have these classes:
>
> class SuperClassManager(models.Manager):
>     def get_by_natural_key(self, identifier):
>         return self.get(identifier=identifier)
>
>
> class SuperClass(models.Model):
>     objects = SuperClassManager()
>
>     identifier = models.CharField(max_length=31, unique=True)
>
>     def natural_key(self):
>         return (self.identifier, )
>
>
> class SubClass(SuperClass):
>     *pass*
>
>
> *class* SubClassTwo(SuperClass):
>     pass
>
> When I do
>
> ./manage.py dumpdata --natural-foreign --natural-primary --indent 4 app
>
> I get:
>
> [
> {
>     "model": "app.superclass",
>     "fields": {
>         "identifier": "one",
>     }
> },
> {
>     "model": "app.superclass",
>     "fields": {
>         "identifier": "two",
>     }
> },
> {
>     "model": "app.subclass",
>     "fields": {}
> },
> {
>     "model": "app.subclasstwo",
>     "fields": {}
> }
> ]
>
> The problem is: superclass of identifier one is a subclass or a 
> subclasstwo? There's no way to tell. Shouldn't the output be
>
> [
> {
>     "model": "app.superclass",
>     "fields": {
>         "identifier": "one",
>     }
> },
> {
>     "model": "app.superclass",
>     "fields": {
>         "identifier": "two",
>     }
> },
> {
>     "model": "app.subclass",
>     "fields": {
>         "superclass_ptr": [
>             "one"
>         ]
>     }
> },
> {
>     "model": "app.subclasstwo",
>     "fields": {
>         "superclass_ptr": [
>             "two"
>         ]
>     }
> }
> ]
>
> Now you can tell that superclass of identifier "two" is actually a 
> subclasstwo!
>
> Now, I did the homework. I digged into the code. :-)
>
> Happens that *OneToOneFields* that are *parent_links* are marked as 
> *serialize=False*, so they never get serialized! Even if you create the 
> field manually in the model, if will still be marked as serialize=False.
>
> Shouldn't *OneToOneFields* that point to parents in *multi-table 
> inheritance* be serialized? Otherwise, how can you tell which subclass is 
> the superclass in the serialized output?
>
> What do you think? Do you think this is an issue to be resolved and, if 
> so, can I submit a pull request?
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5ef1c557-8364-488a-9462-764d4db4f6fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to