Merge pull request 'Пофиксил комменты' (#13) from fix_test into main
Some checks failed
Auto-update README / update-readme (push) Has been cancelled
Some checks failed
Auto-update README / update-readme (push) Has been cancelled
Reviewed-on: #13
This commit is contained in:
commit
f290e5e6a5
@ -76,10 +76,12 @@ class ArticleAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(Comment)
|
@admin.register(Comment)
|
||||||
class CommentAdmin(admin.ModelAdmin):
|
class CommentAdmin(admin.ModelAdmin):
|
||||||
list_display = ('author_name', 'article', 'is_moderated', 'time_create')
|
list_display = ('author_name', 'article', 'parent', 'is_moderated', 'time_create')
|
||||||
list_filter = ('is_moderated', 'time_create')
|
list_filter = ('is_moderated', 'time_create', 'parent')
|
||||||
search_fields = ('author_name', 'author_email', 'content')
|
search_fields = ('author_name', 'author_email', 'content', 'parent__author_name')
|
||||||
actions = ['approve_comments', 'reject_comments']
|
actions = ['approve_comments', 'reject_comments']
|
||||||
|
fields = ('article', 'author_name', 'author_email', 'user', 'parent', 'content', 'is_moderated', 'time_create')
|
||||||
|
readonly_fields = ('time_create',)
|
||||||
|
|
||||||
def approve_comments(self, request, queryset):
|
def approve_comments(self, request, queryset):
|
||||||
queryset.update(is_moderated=True)
|
queryset.update(is_moderated=True)
|
||||||
|
|||||||
@ -42,7 +42,6 @@
|
|||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
{{ form.parent_id }}
|
|
||||||
<button type="submit" class="btn btn-primary">Отправить</button>
|
<button type="submit" class="btn btn-primary">Отправить</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@ -96,6 +96,7 @@ class ArticleDetailView(MenuContextMixin, BreadcrumbMixin, DetailView):
|
|||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
"""Обработка формы комментария."""
|
"""Обработка формы комментария."""
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
print("POST data:", request.POST)
|
||||||
|
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
messages.error(request, "❌ Только авторизованные пользователи могут оставлять комментарии.")
|
messages.error(request, "❌ Только авторизованные пользователи могут оставлять комментарии.")
|
||||||
@ -105,6 +106,7 @@ class ArticleDetailView(MenuContextMixin, BreadcrumbMixin, DetailView):
|
|||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
||||||
parent_id = form.cleaned_data.get('parent_id')
|
parent_id = form.cleaned_data.get('parent_id')
|
||||||
|
print(f"parent_id from cleaned_data: {parent_id}")
|
||||||
parent = None
|
parent = None
|
||||||
|
|
||||||
if parent_id:
|
if parent_id:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user