﻿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
23465	Inheritance destroying data in original model	leandropls	nobody	"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 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. 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."	Bug	closed	Database layer (models, ORM)	1.6	Normal	duplicate			Unreviewed	0	0	0	0	0	0
