开发者

Custom labels for UserProfileForm in Django

I'm using the UserProfileForm class under django.db to take the UserProfile model class and turn it into a form. Currently, the labels for the form elements are the column names of the underlying db table. I'm wondering if there is a way that I can custo开发者_JAVA技巧mize the labels?

Thanks, Tino


I think you mean a model form using django.forms.ModelForm. You can add a verbose name to your UserProfileModel, or you can use the label arg in your ModelForm like so:

>>> class ArticleForm(ModelForm):
...     pub_date = DateField(label='Publication date')
...
...     class Meta:
...         model = Article

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#a-full-example http://docs.djangoproject.com/en/dev/ref/forms/api/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜