Yeah, and I think my suggestion fails for a user-defined rather than
auto-incrementing pk.

On Apr 23, 4:21 pm, Nick Serra <nickse...@gmail.com> wrote:
> A post save signal seems better suited for this. The post save signal
> has an attribute 'created' that will be true or false depending on if
> the object is being created or updated. Check out the post_save
> documentation:http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.si...
>
> On Apr 23, 3:32 pm, Skylar Saveland <skylar.savel...@gmail.com> wrote:
>
>
>
>
>
> > On Apr 23, 3:27 pm, Jim N <jim.nach...@gmail.com> wrote:
>
> > > 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/
>
> > Before you call super you can see if bool(self.pk) is True or False.
> > It will be False before the first save.
>
> > --
> > 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 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> 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 
> athttp://groups.google.com/group/django-users?hl=en.

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