Django admin: hide read-only fields on new records? -
i'm using django admin site readonly fields on records:
class bookadmin(admin.modeladmin): fieldsets = [ (none, {'fields': ['title', 'library_id', 'is_missing', \ 'transactions_all_time']}), ] readonly_fields = ['transactions_all_time',] list_display = ('library_id', 'author', 'title')
this works great when editing records - transactions_all_time
field read-only, want.
however, when adding new records behaves bit oddly. read-only section @ bottom of page, can't edit , irrelevant @ point.
it better if field not present @ when adding new records.
is there django option not displaying read-only fields while adding new record? know can hack css on add_form.html
hide it, there better way?
thanks.
i had similar problem. resolved this
class mymodeladmin(admin.modeladmin): readonly_fields = ('field_one',) def get_readonly_fields(self, request, obj=none): if obj: # editing return self.readonly_fields return ()
Comments
Post a Comment