diff --git a/1_blog/.idea/inspectionProfiles/Project_Default.xml b/1_blog/.idea/inspectionProfiles/Project_Default.xml index f4c49ad..6b7bdc6 100644 --- a/1_blog/.idea/inspectionProfiles/Project_Default.xml +++ b/1_blog/.idea/inspectionProfiles/Project_Default.xml @@ -1,6 +1,16 @@ + + \ No newline at end of file diff --git a/1_blog/post/__init__.py b/1_blog/post/__init__.py index 4cace2f..a9af9da 100644 --- a/1_blog/post/__init__.py +++ b/1_blog/post/__init__.py @@ -14,4 +14,4 @@ def get_current_app_name(_file): class PrimaryBlogConfig(AppConfig): name = get_current_app_name(__file__) - verbose_name = VERBOSE_APP_NAME \ No newline at end of file + verbose_name = VERBOSE_APP_NAME diff --git a/1_blog/post/__pycache__/__init__.cpython-312.pyc b/1_blog/post/__pycache__/__init__.cpython-312.pyc index 34a0390..823b993 100644 Binary files a/1_blog/post/__pycache__/__init__.cpython-312.pyc and b/1_blog/post/__pycache__/__init__.cpython-312.pyc differ diff --git a/1_blog/post/__pycache__/admin.cpython-312.pyc b/1_blog/post/__pycache__/admin.cpython-312.pyc index 0e4c41e..4ca3ab8 100644 Binary files a/1_blog/post/__pycache__/admin.cpython-312.pyc and b/1_blog/post/__pycache__/admin.cpython-312.pyc differ diff --git a/1_blog/post/__pycache__/apps.cpython-312.pyc b/1_blog/post/__pycache__/apps.cpython-312.pyc index 5651891..8931bbd 100644 Binary files a/1_blog/post/__pycache__/apps.cpython-312.pyc and b/1_blog/post/__pycache__/apps.cpython-312.pyc differ diff --git a/1_blog/post/__pycache__/models.cpython-312.pyc b/1_blog/post/__pycache__/models.cpython-312.pyc index 4eae96b..cb9633c 100644 Binary files a/1_blog/post/__pycache__/models.cpython-312.pyc and b/1_blog/post/__pycache__/models.cpython-312.pyc differ diff --git a/1_blog/post/__pycache__/urls.cpython-312.pyc b/1_blog/post/__pycache__/urls.cpython-312.pyc index acdee6e..33d739f 100644 Binary files a/1_blog/post/__pycache__/urls.cpython-312.pyc and b/1_blog/post/__pycache__/urls.cpython-312.pyc differ diff --git a/1_blog/post/__pycache__/views.cpython-312.pyc b/1_blog/post/__pycache__/views.cpython-312.pyc index 47eda62..96de63d 100644 Binary files a/1_blog/post/__pycache__/views.cpython-312.pyc and b/1_blog/post/__pycache__/views.cpython-312.pyc differ diff --git a/1_blog/post/admin.py b/1_blog/post/admin.py index 091cfeb..7a78a3d 100644 --- a/1_blog/post/admin.py +++ b/1_blog/post/admin.py @@ -8,7 +8,10 @@ from .models import * class PostModelAdmin(admin.ModelAdmin): list_display = ('title','created') +class CommentModelAdmin(admin.ModelAdmin): + list_display = ('content','created_at') +admin.site.register(Comment,CommentModelAdmin) admin.site.register(Category) admin.site.register(Tag) admin.site.register(Post,PostModelAdmin) \ No newline at end of file diff --git a/1_blog/post/apps.py b/1_blog/post/apps.py index 469c34e..69463e6 100644 --- a/1_blog/post/apps.py +++ b/1_blog/post/apps.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.apps import AppConfig diff --git a/1_blog/post/models.py b/1_blog/post/models.py index 502e2b9..7fcd85a 100644 --- a/1_blog/post/models.py +++ b/1_blog/post/models.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import models from ckeditor_uploader.fields import RichTextUploadingField @@ -79,3 +76,4 @@ class Comment(models.Model): + diff --git a/1_blog/post/templates/detail.html b/1_blog/post/templates/detail.html index a66aae5..87c281d 100644 --- a/1_blog/post/templates/detail.html +++ b/1_blog/post/templates/detail.html @@ -33,18 +33,20 @@
- - -

Comments

- {% for comment in post.comments.all %} -

{{ comment.author.username }} says: {{ comment.content }}

- {% endfor %} -

Add a comment

-
- {% csrf_token %} - {{ form.as_p }} - -
+ + +

Comments

+ {% for comment in post.comments.all %} +

says: {{ comment.content }}

+ {% endfor %} +

Add a comment

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ + {% endblock %} \ No newline at end of file diff --git a/1_blog/post/views.py b/1_blog/post/views.py index ebf3267..b4e7f78 100644 --- a/1_blog/post/views.py +++ b/1_blog/post/views.py @@ -5,10 +5,20 @@ from django.shortcuts import get_object_or_404, redirect, render # Create your views here. # 渲染主页面 -from post.models import Post +from post.models import Post, Comment from django import forms +# 1111111111111111111111111111111111111111 +from django.forms import ModelForm +from .models import Comment # 假设Comment是你的评论模型 + + +class CommentForm(ModelForm): + class Meta: + model = Comment + fields = '__all__' + def queryAll(request, num=1): num = int(num) @@ -74,8 +84,8 @@ def post_detail(request, pk): if form.is_valid(): comment = form.save(commit=False) comment.post = post - comment.save() - return redirect('detail', pk=post.pk) # 重定向到文章详情页 + form.save() + return redirect('post_comments', pk=post.pk) # 重定向到文章详情页 else: form = CommentForm() @@ -84,7 +94,3 @@ def post_detail(request, pk): 'form': form, } return render(request, 'detail.html', context) - - -class CommentForm(forms.Form): - content = forms.CharField(widget=forms.Textarea(attrs={'rows': '4', 'cols': '60'})) diff --git a/1_blog/templates/footer.html b/1_blog/templates/footer.html index 6cb7efd..7ebbc89 100644 --- a/1_blog/templates/footer.html +++ b/1_blog/templates/footer.html @@ -1,7 +1,7 @@