I have overriden the save method on my model, and want to use the id
field (default autoincrementing pk) to set one of the other fields.

Is this ok:

  class MyModel(models.Model):
    ...
    def save(self, *args, **kwargs):
      super(MyModel, self).save(*args, **kwargs)
      self.some_string_field = "Some text with id=%d" % self.id
      super(MyModel, self).save(*args, **kwargs)

It seems to work, but I'm confused about some side effects.  If I use
  obj, created = MyModel.get_or_create(...)
then created is always False, even when a new object is created.  Is
that because of the 2 super.save() calls?

I guess I could pull this behaviour out of the model, and place into
the view that manipulates it, but I feel the functionality rightfully
belongs in the model.

Any help appreciated.

Thanks,
Richard

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to