views:

39

answers:

1

Hi,

I am using the Django comments framework to allow commenting on articles in a blog. I want to display the title of the article that the comment(s) belongs to in the list view of the comments section where the comment name, content type, object id etc is.

How do I do this? I know you can hook up actions into your admin.py list view by writing a model method but in this case I do not have a model for comments since I am using the built in one.

Thanks

+2  A: 

Somewhere in your code you can override the Comments ModelAdmin class and extend it to do what you want. This code isn't tested, but it should give you a general enough idea about how to customize the Comment admin:

from django.contrib import admin
from django.contrib.comments.admin import CommentsAdmin

class MyCommentsAdmin(CommentsAdmin):

    # The callable that the list_display will call
    def show_object_title(self):
        return self.content_object.title

    list_display = super(MyCommentsAdmin, self).list_display
    list_display += ('show_object_title',)

admin.site.unregister(Comment)
admin.site.register(Comment, MyCommentsAdmin)
robhudson