#23465: Inheritance destroying data in original model
----------------------------------------------+--------------------
Reporter: leandropls | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I've created the following model:
school/models.py:
{{{#!python
from django.contrib.auth.models import User
(...)
class Parent(User):
contract = models.ForeignKey(Contract)
user = models.OneToOneField(User, parent_link = True, related_name =
'school_parent')
}}}
Now I'm trying to "promote" a regular django user into a school parent:
{{{#!python
>>> from django.contrib.auth.models import User
>>> from school.models import Parent, Contract
>>> u = User(username = 'myuser')
>>> u.save()
>>> User.objects.all()
[<User: myuser>]
>>> c = Contract.objects.get(pk = 1)
>>> p = Parent(user = u, contract = c)
>>> p.save()
>>> User.objects.all()
[<User: >]
>>>
}}}
Apparently, in "Parent" creation, the user "myuser" is being destroyed.
Django docs show[1] that you can "attach" one model to other via
OneToOneField the way I'm doing. It also says that multi-table inheritance
automatically creates a OneToOneField[2]. But as I inherit from User and
set its OneToOneField to an existing instance of the user, the specified
existing instance gets destroyed. The expected result was that django
simply made the association.
--
Ticket URL: <https://code.djangoproject.com/ticket/23465>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.c6a88e12776e2fd3c84301c2976d6460%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.