开发者

Custom labels for UserProfileForm in Django

开发者 https://www.devze.com 2023-01-29 03:31 出处:网络
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

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

精彩评论

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