Definitively fix article field in comment admin form

This commit is contained in:
Gabriel Augendre 2020-09-03 22:00:28 +02:00
parent 82dd30e609
commit cb0fa2da94
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
5 changed files with 6 additions and 14 deletions

View file

@ -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).")

View file

@ -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):

View file

@ -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"]

View file

@ -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]

View file

@ -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):