Currently I am developing a blog that contains articles. I wish to add the view count for the articles so that when a user views the article page, that view count will increase.
This is for my models.py file:
class Article(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250,
unique_for_date='publish')
author = models.ForeignKey(User,
on_delete=models.CASCADE,
related_name='kbase_posts')
# body = models.TextField()
#body = RichTextField(blank=True, null=True)
body = RichTextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10,
choices=STATUS_CHOICES,
default='draft')
objects = models.Manager() # The default manager.
published = PublishedManager() # Our custom manager.
tags = TaggableManager()
#topic = models.CharField(max_length=250, blank = True)