Hi,

I have overridden the default save() on a model so that I can update
some counts every time a save occurs.  Unfortunately, I don't want to
perform these actions every time the model is updated, which seems to
happen.

Is there another approach I can take that distinguishes between save
and update?

class Answer(models.Model):
    answer = models.TextField()
    user = models.ForeignKey(User, null=True)
    submit_date = models.DateTimeField('Date Submitted',
default=datetime.datetime.now)
    question = models.ForeignKey(Question)
    permalink = models.CharField(max_length=300, blank=True)


    def save(self, *args, **kwargs):
        super(Answer, self).save(*args, **kwargs) # Call the "real"
save() method.
        if(self.user):
            quser = self.user.get_profile()
            quser.increment_answers()   # <-- I don't want to do this
on an update.
            self.question.increment_responses() # <-- I don't want to
do this either.


Or in more readable form: http://dpaste.de/I2IR/


TIA!

-Jim

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