I have excluded a field like this in order to set it’s label.
class ContactsForm(ModelForm):
marital_status = forms.ModelChoiceField(label=_(u'Marital Status'), queryset=MaritalStatus.objects.all())
class Meta:
model = Contact
exclude = ('marital_status',)
This works, however marital status now appears at the very end of the form after all other elements.
Is there a way to specify the field’s position?
Alternatively I didn’t even have to exclude the field in first place, if I was able to set the label within the model it self, like the example below, where I set the label “Day of Birth”. I can’t seem to be able to set the label for models.ForeignKey, any idea?
marital_status = models.ForeignKey(MaritalStatus)
birth_date = models.DateField(_(u"Day Of Birth"), blank=True)
You can use ‘verbose_name’ attribute while defining foreign key, which will be displayed as label in the form.
Ref: https://docs.djangoproject.com/en/dev/topics/db/models/#verbose-field-names