jvc26
jvc26

Reputation: 6503

How to administer comment flags in django

I have django's comment framework enabled, and I have flagging urls set up:

comments/flag/{{comment.id}}/

The comments are registered, and appear in the database. However, they are not appearing in the admin interface. What would be ideal would be to add the filter for the comment 'flagged' status in the admin interface, but am not sure exactly how to do this.

Upvotes: 0

Views: 788

Answers (1)

yonomitt
yonomitt

Reputation: 204

I was looking for a solution to this exact problem when I found your question.

I used some tips from Django - Extending another apps ModelAdmin?

I created an admin.py file in main app directory. Here are the contents:

from django.contrib import admin
from django.contrib.admin.sites import NotRegistered
from django.contrib.comments.models import Comment

try:
    admin.site.unregister(Comment)
except NotRegistered:
    pass

from django.contrib.comments.admin import CommentsAdmin

try:
    admin.site.unregister(Comment)
except NotRegistered:
    pass

class MyCommentsAdmin(CommentsAdmin):

    def flag(self, obj):
        flag_name = ''
        try:
            flag_name = obj.flags.values()[0]['flag']
        except IndexError:
            pass
        return flag_name

    list_display = ('name', 'content_type', 'object_pk', 'ip_address', 'submit_date', 'flag', 'is_public', 'is_removed')
    list_filter = ('submit_date', 'site', 'is_public', 'is_removed', 'flags__flag')

admin.site.register(Comment, MyCommentsAdmin)

This will add a column to the Comment list called 'Flag', which will show the name of the first flag on the comment, if one exists. The list_filter line adds a new filter to the right hand side in the admin site that allows you just to show particular flags.

Upvotes: 5

Related Questions