diff --git a/forum/migrations/0004_post_views.py b/forum/migrations/0004_post_views.py new file mode 100644 index 0000000..c6277ff --- /dev/null +++ b/forum/migrations/0004_post_views.py @@ -0,0 +1,18 @@ +# Generated by Django 6.0.2 on 2026-02-23 08:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('forum', '0003_alter_comment_content_alter_item_description_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='views', + field=models.PositiveIntegerField(default=0), + ), + ] diff --git a/forum/models.py b/forum/models.py index ce6e5ff..53e7cfb 100644 --- a/forum/models.py +++ b/forum/models.py @@ -27,6 +27,7 @@ class Post(MarkdownModel): author = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=100) created_at = models.DateTimeField(auto_now_add=True) + views = models.PositiveIntegerField(default=0) def __str__(self): return f"{self.title} by {self.author}" diff --git a/forum/templates/forum/post_detail.html b/forum/templates/forum/post_detail.html index 3d11b0e..9703929 100644 --- a/forum/templates/forum/post_detail.html +++ b/forum/templates/forum/post_detail.html @@ -13,6 +13,8 @@

{{ post.title }}

{{ post.author.username }}   |   {{ post.created_at|date:"Y-m-d H:i" }} +   |   + {{ post.views }} {% if can_delete %} diff --git a/forum/templates/forum/post_list.html b/forum/templates/forum/post_list.html index 73fda9f..e3b624c 100644 --- a/forum/templates/forum/post_list.html +++ b/forum/templates/forum/post_list.html @@ -8,7 +8,7 @@

所有文章