5👍
✅
The automatically created primary key field works just like any other field, except that you don’t have to specify it. Unless you’ve changed the name, this should be as simple as:
list_display = ['id', ...]
I haven’t checked on whether or not the pk
alias works everywhere that the admin expects field names.
UPDATE: the pk
alias is accepted instead of id
6👍
Yes, in the list_display
field, you can add the pk
field.
To make it linkable, you can use the list_display_links
field
class MyModelAdmin(admin.ModelAdmin):
list_display = ('pk', 'name', 'email', ...) #You can use 'pk' or 'id'
list_display_links = ('pk', ) #the same here - 'pk' or 'id'
admin.register(MyModel, MyModelAdmin)
- [Django]-How can I use regex in django's Replace function
- [Django]-Using Django RelatedField for custom join queries?
- [Django]-Is there a Django template filter that turns a datetime into "5 hours ago" or "12 days ago"?
Source:stackexchange.com