python - Debugging Django admin panel bug -
when navigate admin interface particular model (the whole-table view), , hit 'save', error popping on usual red banner:
please correct errors below.
needless couldn't make edits view, until experimented , fixed it.
here's class:
class rolemapping(models.model): min_length, max_length = 3, 40 role_name = models.charfield(unique=true, max_length=max_length, validators = [ minlengthvalidator(min_length, "field length should greater {}".format(min_length)) ]) role_type = models.foreignkey(roletype, null=true, blank=true )
here's admin interface model. but, flipping around of editable fields seems have made things work.
class rolemapping(admin.modeladmin): model = rolemapping list_display = ('role_name', 'role_type',) #list_editable = ('role_name', 'role_type',) # fails #list_editable = ('role_name',) # fails list_editable = ('role_type',) # works?!
i can working, pretty easily, keeping role_type editable type. however, found out after bit of trial , error. i'm wondering:
what's django way of debugging these sorts of admin-panel-orm issues in future
why might have been failing in first place?
according the django admin docs:
note:
list_editable
interacts couple of other options in particular ways; should note following rules:
- any field in
list_editable
must inlist_display
. can’t edit field that’s not displayed!- the same field can’t listed in both
list_editable
,list_display_links
– field can’t both form , link.you’ll validation error if either of these rules broken.
my guess violating second point , role_name
default sole member of list_display_links
.
to test this, set list_display_links = none
or make field , add list_display
, list_display_links
.
edit:
i suspect following give want. i've added id
first element of list_display
. behind scenes, adds id
instead of role_name
list_display_links
, frees role_name
allowed in list_editable
.
class rolemapping(admin.modeladmin): model = rolemapping list_display = ('id', 'role_name', 'role_type',) list_editable = ('role_name', 'role_type',)
Comments
Post a Comment