Opened 8 years ago
Last modified 8 years ago
#28059 closed Bug
Admin page cannot render horizontal radio buttons — at Initial Version
Reported by: | Musen | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.11 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
To reproduce the bug, suppose we have the model Person
defined in models.py
class Person(Models.model): age = CharField(choices = (('Y', 'Young'), ('O', 'Old')))
We want to display the choice of age in our admin change page in radio buttons, so we have the following codes in admin.py
from .models import Person class PersonAdmin(admin.ModelAdmin): radio_fields = {'age': admin.HORIZONTAL} admin.site.register(Person, PersonAdmin)
Then, we will get the vertical radio buttons instead of the horizontal ones.
The bug is caused by the wrong HTML attribute that the ModelAdmin
uses to produce horizontal radio buttons. The correct attribute is radio-inline
but ModelAdmin
uses radiolist inline
. Also, since HTML uses the vertical radio buttons as default, function get_ul_class
is useless, and it can be simply replaced by an if statement.