Malcolm Tredinnick escribió: > The Model class calls pre_save() to work out the value to save into the > database. That's working correctly for you, as you've noticed: the right > value is being saved. > > Some Field subclasses in Django also use pre_save() as a way to > normalise the value in the Model attribute. It sounds like you want that > to happen -- you would be normalising it from "nothing at all" to the > correct value. In that case, you need to call setattr() to set the > attribute value. That's why model_instance is passed as a parameter to > pre_save(). You could write something like this: > > def pre_save(self, model_instance, add): > if self.prepopulate_from: > value = slugify(model_instance, self, > getattr(model_instance, self.prepopulate_from), > self.force_update) > else: > value = super(AutoSlugField, > self).pre_save(model_instance, > add) > setattr(model_instance, self.attname, value) > return value > > Does that clear things up? > > Regards, > Malcolm
Great, that did the trick :) Thanks for the tip! Regards. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---

