model inheritance

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django.contrib.auth.models import User
class Profile(User):
some_additional_profile_field = models.IntegerField()
class Admin:
pass
def __unicode__(self):
return '%s %s' % (self.first_name, self.last_name)
In [12]: User.objects.all()
Out[12]: [<User: root>]
In [13]: Profile.objects.all()
Out[13]: []
In [14]: root = User.objects.get(username='root')
In [15]: root.pk
Out[15]: 1
In [16]: p = Profile(user_ptr=root)
In [17]: p.karma = 10
In [18]: p.save()
In [19]: User.objects.all()
Out[19]: [<User: >, <User: root>]
WTF?!