Manually Update DateTimeField

python Dec. 18, 2015, 9:24 p.m.

# on model:
class Topic(models.Model):
    edited = models.DateTimeField()
    lastreply = models.DateTimeField(blank=True,null=True)

    def save(self, *args, **kwargs):
        if not kwargs.pop('skip_ubah',False):

        super(Topic, self).save(*args, **kwargs)

# on reply
class Reply(models.model):
    topik=models.ForeignKey (Topik, related_name='replytopik')

    def save(self, *args, **kwargs):
        topik = Topic.objects.get(pk=self.topik_id)
        topik.lastuser = self.user.username                   )
        super(Reply, self).save(*args, **kwargs)

I need to update a parent model without changing its last edit..this snippet will always auto update that parent unless argument 'skip_ubah' is given. Useful when you want to make sure that only direct modification is recorded, but not on signal.

Any thoughts?