On Wed, May 7, 2008 at 1:00 AM, Alen Ribic <[EMAIL PROTECTED]> wrote:
>
>  At this moment, to my knowledge, the only way to do this is by
>  overriding the save() method. Within your save, run the pre-save work
>  and then return the super.save().

Well - there is one other way: the default argument on a field. For example:

   position = models.IntegerField(blank=True, default=1)

You can also pass a callable:

from datetime import datetime
...
   pub_date = models.DateField(default=datetime.now)

Here, datetime.now() is a function; it will be invoked when the model
is saved to get the current value.

This won't work so well for your slots_available field, because it
requires access to the 'parent' field of the instance being saved. In
that case, overriding save() will be the best approach. If you for "id
is None" in the save() method, that will tell you whether the object
has been saved before, because the best marker for a new object is
that the PK hasn't been set yet.

You _could_ do all this with signals, but it's a bit over the top IMHO.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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