Shaumux
Shaumux

Reputation: 745

Display single record in django modeladmin

I want to implement something like this: I have model A admin with a status field which is a link to the model B admin. Now when i click on column for the row with link for model B admin it should go to model B admin which it is currently doing but it should only display a single record out of all the records model B for which i clicked. Model A contains a Foreign Key for model B's record and that is the record which should be displayed in the admin view

Upvotes: 0

Views: 243

Answers (1)

Prashant Gaur
Prashant Gaur

Reputation: 9828

i will suggest you to do something like below i am doing .
Django admin provided you to create a method of particular field name which you have defined into list_display.
In that method you are ovveride return content for that field like below.

class AAdmin(admin.ModelAdmin):
    list_display = ('id', 'email_settings')
    """ """
    def email_settings(self, obj):
         from django.core.urlresolvers import reverse
         return '%s'%('/admin/core/emailsetting/?id='+str(obj.email_setting.id), obj.email_setting.id)
    email_settings.allow_tags = True
    email_settings.short_dscription = "Email Setting Link"

Here you can see url is hardcoded . You can use _meta to get app name and model name . Example :

 obj._meta.app_name

Upvotes: 2

Related Questions