Opened 10 years ago
Closed 10 years ago
#24888 closed Uncategorized (worksforme)
A charfield with options shows with short tags in stead of verbose name in a modelform
| Reported by: | Wim Feijen | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | 1.8 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Suppose you have a charfield in your model which has several choices defined. When you create a form from this model, the form shows the short tags as options (which are used for database storage) in stead of the verbose name (get_xxx_display) which should be used by default for displaying, in my opinion.
Example:
FURNISHING = (
("yes", _("Furnished")),
("no", _("Unfurnished")),
("bare", _("Bare")),
)
class Room(TimeStamped):
...
furnishing = models.CharField(verbose_name=_("furnishing"), max_length=10, choices=FURNISHING, default='no')
...
FIELDS = [..., 'furnishing', ...]
class RoomForm(forms.ModelForm):
class Meta:
model = Room
fields = FIELDS
widgets = {
'furnishing': forms.RadioSelect(),
}
(A workaround is to use the verbose names as char tags in the database. However, this does not work in a multilingual environment.)
Note:
See TracTickets
for help on using tickets.
Here's the HTML I get with the code your provided (using
return render(request, 'form.html', {'form': RoomForm()})as the view and{{ form }}in the template):This seems to be the expected result. Please reopen if you can provide more specific steps to reproduce.