Thanks, Alex. Do you know anything about pre_save and post_save signals that occur during a save? They are mentioned here: http://www.djangoproject.com/documentation/db-api/#what-happens-when-you-save, but are not expounded.
Also I modified my code (under the assumption that pk would be None for newly created models): if self.pk == None: self.slots_available = self.storage_unit_type.total_slots self.position = 1 On May 6, 10: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(). > > I have suggested a pre_save / post_save hooks for ModelForm with some > code recently > here:http://groups.google.com/group/django-developers/browse_thread/thread... > > -Alen Ribic > > On May 6, 6:50 pm, Jashugan <[EMAIL PROTECTED]> wrote: > > > I'd like to set some attributes to some default values before the > > model is created. Here's what I have so far: > > > slots_available = models.IntegerField(blank=True) > > position = models.IntegerField(blank=True) > > > def save(self): > > if slots_availalbe == None: > > slots_available = > > StorageUnitType.objects.get(pk=parent).total_slots > > if position == None: > > position = 1 > > super(StorageUnit, self).save() > > > Is this the best way of doing this? Is there a way I can specify that > > this code should run only when a model is first saved? I read > > something about using listeners for some post and pre save signals, > > but wasn't able to find any documentation on it. > > > TIA --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---