bit worrying that you consider the traceback to be 'gumph' but since
the error says specifically that the 'created' column cannot be null,
it sounds like your DB and model are out of sync.

as for the actual problem, you'll have to appreciate that creating a
'User' also creates a 'Person', who's attributes are blank.  when you
alter the parent id you're invsivibly altering the reference to that
new 'Person' and when the systems checks to see if it's changed it
saves the new person (with blank values) over the existing one.
essentially, you have to realise that you are not creating a new
'User'.

there are a couple of ways to munge the logic to make it work but i'm
sure you'll figure out what's best for your own scenario.

On Nov 30, 1:24 pm, Fergus <[EMAIL PROTECTED]> wrote:
> 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