Definitively fix article field in comment admin form
This commit is contained in:
parent
82dd30e609
commit
cb0fa2da94
5 changed files with 6 additions and 14 deletions
|
@ -126,11 +126,6 @@ class CommentAdmin(admin.ModelAdmin):
|
|||
search_fields = ("username", "email", "content")
|
||||
actions = ["approve_comments", "reject_comments"]
|
||||
|
||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||
if db_field.name == "article":
|
||||
kwargs["queryset"] = Article.with_pages.all()
|
||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
|
||||
def approve_comments(self, request, queryset):
|
||||
count = queryset.update(status=Comment.APPROVED, user_notified=False)
|
||||
messages.success(request, f"Approved {count} message(s).")
|
||||
|
|
|
@ -6,7 +6,7 @@ def pages(request):
|
|||
|
||||
|
||||
def drafts_count(request):
|
||||
return {"drafts_count": Article.with_pages.filter(status=Article.DRAFT).count()}
|
||||
return {"drafts_count": Article.objects.filter(status=Article.DRAFT).count()}
|
||||
|
||||
|
||||
def date_format(request):
|
||||
|
|
|
@ -50,8 +50,8 @@ class Article(AdminUrlMixin, models.Model):
|
|||
slug = models.SlugField(unique=True, max_length=255)
|
||||
comments_allowed = models.BooleanField(default=True)
|
||||
|
||||
objects = ArticleManager()
|
||||
with_pages = models.Manager()
|
||||
objects = models.Manager()
|
||||
without_pages = ArticleManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ["-published_at"]
|
||||
|
|
|
@ -10,7 +10,7 @@ class CompleteFeed(Feed):
|
|||
description = settings.BLOG["description"]
|
||||
|
||||
def items(self):
|
||||
return Article.objects.filter(status=Article.PUBLISHED).order_by(
|
||||
return Article.without_pages.filter(status=Article.PUBLISHED).order_by(
|
||||
"-published_at"
|
||||
)[:15]
|
||||
|
||||
|
|
|
@ -14,21 +14,19 @@ class ArticlesListView(generic.ListView):
|
|||
model = Article
|
||||
paginate_by = 15
|
||||
context_object_name = "articles"
|
||||
queryset = Article.without_pages.filter(status=Article.PUBLISHED)
|
||||
|
||||
def get_context_data(self, *, object_list=None, **kwargs):
|
||||
context = super().get_context_data(object_list=object_list, **kwargs)
|
||||
context["title"] = "Articles"
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(status=Article.PUBLISHED)
|
||||
|
||||
|
||||
class DraftsListView(generic.ListView, LoginRequiredMixin):
|
||||
model = Article
|
||||
paginate_by = 15
|
||||
context_object_name = "articles"
|
||||
queryset = Article.with_pages.filter(status=Article.DRAFT)
|
||||
queryset = Article.objects.filter(status=Article.DRAFT)
|
||||
|
||||
def get_context_data(self, *, object_list=None, **kwargs):
|
||||
context = super().get_context_data(object_list=object_list, **kwargs)
|
||||
|
@ -40,7 +38,6 @@ class ArticleDetailView(FormMixin, generic.DetailView):
|
|||
model = Article
|
||||
form_class = CommentForm
|
||||
context_object_name = "article"
|
||||
queryset = Article.with_pages.all()
|
||||
template_name = "articles/article_detail.html"
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
Reference in a new issue