class Post(models.Model):
views = models.IntegerField(("View count"), default=0, editable=False)
def viewed(self):
self.views += 1
self.save(update_fields=['views'])
def viewed(self):
type(self).objects.filter(id=self.id).update(views=F('views') + 1)
class Post(models.Model):
views = models.IntegerField(("View count"), default=0)
def viewed(self):
if self.views:
self.views += 1
else:
self.views = 1
self.save(update_fields=['views'])