Fix pages not displayed in comment admin form

This commit is contained in:
Gabriel Augendre 2020-09-03 21:15:59 +02:00
parent 7fe208f5d3
commit e247f15797
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 9 additions and 1 deletions

View file

@ -125,6 +125,11 @@ class CommentAdmin(admin.ModelAdmin):
search_fields = ("username", "email", "content") search_fields = ("username", "email", "content")
actions = ["approve_comments", "reject_comments"] 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): def approve_comments(self, request, queryset):
count = queryset.update(status=Comment.APPROVED, user_notified=False) count = queryset.update(status=Comment.APPROVED, user_notified=False)
messages.success(request, f"Approved {count} message(s).") messages.success(request, f"Approved {count} message(s).")

View file

@ -56,7 +56,10 @@ class Article(AdminUrlMixin, models.Model):
ordering = ["-published_at"] ordering = ["-published_at"]
def __str__(self): def __str__(self):
return self.title type_ = "Article"
if hasattr(self, "page"):
type_ = "Page"
return f"{self.title} ({type_})"
def get_admin_url(self): def get_admin_url(self):
content_type = ContentType.objects.get_for_model(self.__class__) content_type = ContentType.objects.get_for_model(self.__class__)