I have Django CMS 2.1.3 installed. It has among many models:
from django.contrib.auth.models import User, Group
# (...)
class PageUser(User):
"""Cms specific user data, required for permission system
"""
created_by = models.ForeignKey(User,
related_name="created_users")
class Meta:
verbose_name = _('User (page)')
verbose_name_plural = _('Users (page)')
app_label = 'cms'
#__unicode__ = lambda self: unicode(self.user)
And this is how the beginning of the parent model looks (Django 1.2.5,
django/contrib/auth/models.py):
class User(models.Model):
"""
Users within the Django authentication system are represented by
this model.
Username and password are required. Other fields are optional.
"""
username = models.CharField(_('username'), max_length=30,
unique=True, help_text=_("Required. 30 characters or fewer. Letters,
numbers and @/./+/-/_ characters"))
first_name = models.CharField(_('first name'), max_length=30,
blank=True)
last_name = models.CharField(_('last name'), max_length=30,
blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
password = models.CharField(_('password'), max_length=128,
help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=
\"password/\">change password form</a>."))
is_staff = models.BooleanField(_('staff status'), default=False,
help_text=_("Designates whether the user can log into this admin
site."))
is_active = models.BooleanField(_('active'), default=True,
help_text=_("Designates whether this user should be treated as active.
Unselect this instead of deleting accounts."))
is_superuser = models.BooleanField(_('superuser status'),
default=False, help_text=_("Designates that this user has all
permissions without explicitly assigning them."))
last_login = models.DateTimeField(_('last login'),
default=datetime.datetime.now)
date_joined = models.DateTimeField(_('date joined'),
default=datetime.datetime.now)
groups = models.ManyToManyField(Group, verbose_name=_('groups'),
blank=True,
help_text=_("In addition to the permissions manually
assigned, this user will also get all permissions granted to each
group he/she is in."))
user_permissions = models.ManyToManyField(Permission,
verbose_name=_('user permissions'), blank=True)
objects = UserManager()
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
#(...)
So how does Django handle model inheritance? To my understanding, if
nothing is stated in the Meta class, it will use multitable
inheritance (
http://docs.djangoproject.com/en/dev/topics/db/models/
#multi-table-inheritance).
So in this particular case, the cms_userpage table should NOT contain
any information defined in the class User. Right?
However when I run "manage.py sqldiff cms" I get:
-- Model: PageUser
ALTER TABLE "cms_pageuser"
ADD "username" varchar(30);
ALTER TABLE "cms_pageuser"
ADD "first_name" varchar(30);
ALTER TABLE "cms_pageuser"
ADD "last_name" varchar(30);
ALTER TABLE "cms_pageuser"
ADD "is_active" boolean;
ALTER TABLE "cms_pageuser"
ADD "email" varchar(75);
ALTER TABLE "cms_pageuser"
ADD "is_superuser" boolean;
ALTER TABLE "cms_pageuser"
ADD "is_staff" boolean;
ALTER TABLE "cms_pageuser"
ADD "last_login" timestamp with time zone;
ALTER TABLE "cms_pageuser"
ADD "password" varchar(128);
ALTER TABLE "cms_pageuser"
ADD "id" serial;
ALTER TABLE "cms_pageuser"
ADD "date_joined" timestamp with time zone;
ALTER TABLE "cms_pageuser"
ADD UNIQUE ("id");
ALTER TABLE "cms_pageuser"
ADD UNIQUE ("username");
It looks like sqldiff thinks that the table of the child model should
inherit all information from the parent model.
Have I misunderstood something? Or how can this be explained?
I am using Django Extensions 0.4.1.
Sincerely, Thomas Wessel