implemented viewcount

This commit is contained in:
CDaut 2022-09-12 00:37:42 +02:00 committed by CDaut
parent a8b2b6d1c0
commit dab1a625c6
6 changed files with 24 additions and 2 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 4.0.5 on 2022-09-11 22:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('blog', '0002_alter_blogpost_title_alter_tag_name_alter_topic_name'),
]
operations = [
migrations.AddField(
model_name='blogpost',
name='views',
field=models.IntegerField(default=0),
),
]

View file

@ -30,3 +30,4 @@ class Blogpost(models.Model):
tags = models.ManyToManyField(Tag)
topic = models.ForeignKey(Topic, blank=True, null=True, on_delete=models.CASCADE)
mdfile = models.CharField(max_length=255)
views = models.IntegerField(default=0)

View file

@ -32,6 +32,8 @@ def render_md_file(path) -> Template:
def viewblog(request, title) -> HttpResponse:
post = Blogpost.objects.get(title=title)
post.views += 1
post.save()
filepath = os.path.join(os.environ.get("MD_FILE_PATH"), title + ".md")
rendered_html = render_md_file(filepath)