Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change clickable field in Django admin list_display

Tags:

In Django 1.8.6, by default, whenever I provide a list_display option to a ModelAdmin subclass, the first field in the list becomes clickable and leads to the object edit page.

Is there a way to keep the order of the fields in list_display, but change the clickable one?

Currently, I have the id field clickable (it goes first in list_display), which is a tad small. I would like to better click on, say, name to go to the edit page.

like image 893
wh1t3cat1k Avatar asked Nov 09 '15 19:11

wh1t3cat1k


People also ask

How do I make a field editable in Django?

To use editable in a field you must specify either of following settings: null=True and blank=True, so that your field doesn't give required error during model save.

Can we customize Django admin panel?

The Django admin is a powerful built-in tool giving you the ability to create, update, and delete objects in your database using a web interface. You can customize the Django admin to do almost anything you want.

How do I change the admin heading in Django?

To change the admin site header text, login page, and the HTML title tag of our bookstore's instead, add the following code in urls.py . The site_header changes the Django administration text which appears on the login page and the admin site. The site_title changes the text added to the <title> of every admin page.

How do you make a field non mandatory in Django admin?

The simplest way is by using the field option blank=True (docs.djangoproject.com/en/dev/ref/models/fields/#blank).


1 Answers

You could have a look at django.contrib.admin.ModelAdmin.list_display_links

Basically it is used like

class PersonAdmin(admin.ModelAdmin):     list_display = ('first_name', 'last_name', 'birthday')     list_display_links = ('first_name', 'last_name') 

Hope this will help :)

like image 94
Xiaoqi Chu Avatar answered Oct 02 '22 06:10

Xiaoqi Chu