Reputation: 33
how can we increment the counter when an entry occurs in the comments Class???
class Status(models.Model):
status = models.CharField(max_length=140)
counter = models.IntegerField(default=0)
class Comments(models.Model):
status = models.ForeignKey(status)
comment = models.CharField(max_length=140)
Upvotes: 2
Views: 222
Reputation: 2569
You can override your save method
class Comments(models.Model):
status = models.ForeignKey(status)
comment = models.CharField(max_length=140)
def save(self, *args, **kwargs):
#get the status
#save it
#Call super save to store your comment
super(Comments, self).save(*args, **kwargs)
Upvotes: 0
Reputation: 22469
Either by using a signal or adding it to the processing method of (saving) comments.
Upvotes: 4