Check out get_FOO_display, there: https://docs.djangoproject.com/en/dev/ref/models/instances/
Oh, sorry, I must have misunderstood then.
I remember reading a post on thread on SO that addressed this, and I believe that they came up with a template filter as there was no "simple" way to do it.
Here it is: http://stackoverflow.com/questions/1105638/django-templates-verbose-version-of-a-choice
Hope this helps!
Like they do in the admin, right ?
You might want to check Django's source for the admin forms and templates to get some inspiration then.
Hard coding the choices is never a satisfactory solution but I suggest you retrieve them from your models file so you stay DRY compliant and then it's pretty OK.
As you put the widget in your field I think you just need to put form.branch_name to get it to display.
--You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
That didn't help either. It still did not depict what I'm trying to do. Those filters are for retrieving values set by a user. However, I tried the code below which is to hard code the choices into the form field on creationclass TransactionUpdateForm(forms.ModelForm):branch_name_new = forms.models.CharField(required=True, widget=forms.Select(choices={'BR_CODE1': 'HQ','BR_CODE2': 'Branch 2'}))class Meta:model = Transactionfields = ('branch_name')widgets = {'branch_name_new': Select(choices={'BR_CODE1': 'HQ': 'Branch 2'}),}In the template, I did an output like this: {{form.branch_name_new}}. Nothing gets displayed.How does Django handle this literally. I have read the docs insideout and tried stuffs out as written, but nothing seem to work. Has anyone done this sort of stuff before - I mean this is meant to be basic stuff. I don't want to have to manually create HTML markups in the template, because I will be needing those Select field values coming from the db.Thanks
This exact question gets asked about 3 times a week (well, once you
have normalized out the different ways in which it is asked..).
Personally, I'm fed up of answering it.
I think that adjusting the labels needs to become a bit more flexible
- perhaps allow a "label_from_instance=callable" argument on
ModelChoiceField, or have ModelChoiceField look for a
MyForm.label_from_instance_<fieldname> method.
The current options are
a) change how the related field's model is displayed throughout Django
(which may be impossible to do for a cross app links/3rd party apps)
b) provide your own Field class which labels things appropriately
Both these options are more cumbersome than needs be, as evidenced by
the number of users who don't understand how to do this.
Cheers
Tom
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.