I've created the following model:
school/models.py:
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:
>>> 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].
Is there a way to "promote" a User to Parent in this case? What about demotion?
Reference:
p.user.name; with inheritance:p.name. Making the OTO field of inheritance explicit, you can specify it's properties, likerelated_name.