I have an inheritance system for defining people.

So there's a class Person, and sub-class User thus:

class Person(models.Model):
    ''' A person! '''

    firstname = models.CharField("first name", max_length = 128,
help_text = "(required)")
    lastname = models.CharField("last name", max_length = 128,
help_text = "(required)")
    email = models.EmailField("email address", unique = True,
help_text = "(required)")
    groups = models.ManyToManyField(Group, blank = True, through =
'Membership', related_name = 'group_set', verbose_name = "group
memberships")

    created = models.DateTimeField(auto_now_add = True)
    last_modified = models.DateTimeField(auto_now = True)

class User(Person):
    ''' Persons who are also users '''

    password = models.CharField(max_length = 40, blank = True,
editable = False)

I would like to add child classes after previously having an object as
only a parent - so at some point in time a Person can become a User.
So I try this in the manage.py shell:

>>> from MyPidge.Users.models import Person, User
>>> myuser = Person.objects.create(firstname = "Fergus", lastname = "Ferrier", 
>>> email = "[EMAIL PROTECTED]")
>>> myuser.save()

After myuser.save() there is a Person row in the DB, and all appears
well.

>>> newu = User(password = "hello")
>>> newu.person_ptr_id = myuser.id
[ also tried person = myuser and person_ptr = myuser]
>>> newu.save()
... Traceback gumph ...
Warning: Column 'created' cannot be null

There is no User row, and the Person row now has blank values except
for the last modified field.

Please tell me if I've done something totally crazy. I only want to
add children after-the-fact...

Many thanks,
Ferg
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to