Question

in django admin the views that show the register's just have a link to "edit", but what happen if a need an extra(S) links to another views? for example: i have view that show the list of registered People, the nick is linking to the Edit page (the normal way of Django), but i need another links that will show me the "articles" of the people and another the "comments" of the people. how ill make this with django admin? Thanks

Was it helpful?

Solution

(I'm assuming some field names from your models to answer)

Make the author field from "comment" searchable:

class CommentAdmin(admin.ModelAdmin):
   search_fields = ("=author",)

Use list_display and HTML to control what's displayed on the people's list admin page:

def comments(obj):
    return ('<a href="/admin/pathto/comments/?q=%s">comments</a>' % obj.name)
comments.short_description = 'comments'
comments.allow_tags = True

class PeopleAdmin(admin.ModelAdmin):
    list_display = ("name", comments,)

And change /admin/pathto/comments/ to whatever your comment's admin list page is.

Basically you're going to direct your users to the comments search result page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top