Edit/show Primary Key in Django Admin

后端 未结 6 974
时光取名叫无心
时光取名叫无心 2020-12-28 14:12

It appears Django hides fields that are flagged Primary Key from being displayed/edited in the Django admin interface.

Let\'s say I\'d like to input data in which I

6条回答
  •  一生所求
    2020-12-28 14:55

    I also wanted to simply show the 'id' (primary key) within the Django admin, but not necessarily edit it. I just added it to the readonly_fields list, and it showed up fine. IE:

    class StudentEnrollmentInline(admin.TabularInline):
        model = Enrollment
        readonly_fields=('id',)
    

    whereas if I tried to add it to the 'fields' list, Django got upset with me, saying that field didn't exist...

提交回复
热议问题