G
G
GizzaProger2019-12-28 22:27:35
Django
GizzaProger, 2019-12-28 22:27:35

How to display post id in django admin panel?

Can't display id in django admin panel. I know that he himself assigns id to new records, but displays only those that I specified in the model. Tried through fields = ["id"], but output, there is no such field. I tried to specify it in the model, but the result is the same. I would also like to display it not only when editing posts, but also in the title of the post in the preview. I don’t want to click and go to the page of a specific post every time to see the id . Please help solve the problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2019-12-28
@GizzaProger

class MyModelAdmin(admin.ModelAdmin):
    readonly_fields = ('id',)

admin.site.register(MyModel, MyModelAdmin)

V
Vladimir, 2019-12-29
@RivalCode

So that the id is in the list

class MyModelAdmin(admin.ModelAdmin):
    list_display = ('id', ) # нужно указать все остальные нужные поля

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question