On Monday, 8 August 2011 13:06:51 UTC+1, Kayode Odeyemi wrote: > > 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 creation > > class 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 = Transaction > fields = ('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 > > I'm afraid it's really not clear what you're trying to do, or what the problem is.
If the issue is that you have a field referring to a foreign key, and you want to change what the values displayed in the dropdown for that field, then you simply need to redefine the `__unicode__` method for the related model, as documented here: https://docs.djangoproject.com/en/1.3/ref/forms/fields/#modelchoicefield An alternative, also documented at that link, is to subclass ModelChoiceField and override label_from_instance. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/yOF_rPJgfhIJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.