Fix pages not displayed in comment admin form
This commit is contained in:
parent
7fe208f5d3
commit
e247f15797
2 changed files with 9 additions and 1 deletions
|
@ -125,6 +125,11 @@ 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).")
|
||||
|
|
|
@ -56,7 +56,10 @@ class Article(AdminUrlMixin, models.Model):
|
|||
ordering = ["-published_at"]
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
type_ = "Article"
|
||||
if hasattr(self, "page"):
|
||||
type_ = "Page"
|
||||
return f"{self.title} ({type_})"
|
||||
|
||||
def get_admin_url(self):
|
||||
content_type = ContentType.objects.get_for_model(self.__class__)
|
||||
|
|
Reference in a new issue