python - Django Admin, missing id readonly field in StackedInline -
i have stackedinline model contains several fields (including 'id' field):
class myinline(admin.stackedinline): model= mymodel fields = ('id', 'foo', 'bar')
this shows 3 editable fields expected, however, when setting readonly
:
class myinline(admin.stackedinline): model= mymodel fields = ('id', 'foo', 'bar') readonly_fields= ('id','foo','bar')
the id field missing, foo
, bar
appear (as non-editable).
this behaviour happened when using stackedinline
, tabularinline
works fine
why id missing , how can add readonly field?
first check mymodel
model has foreign key model in declared inlines = [mymodel]
.
something that:
# models.py class album(models.model): # various fields here class autoid(models.model): id = models.charfield(primary_key=true, max_length=10) album = models.foreignkey(album, blank=true, null=true) foo = models.charfield(max_length=12) # admin.py class autoidinline(admin.stackedinline): model = autoid fields = ('id', 'foo', ) readonly_fields = ('id', 'foo', ) @admin.register(album) class albumadmin(admin.modeladmin): inlines = [autoidinline]
with set, using django 1.11 , dummy values id
primary key, should (tested locally , works charm):
Comments
Post a Comment