how can I change the modelform label and give it a custom name

前端 未结 4 553
慢半拍i
慢半拍i 2020-12-29 19:23

I want to create a custom name for on of the labels in my modelform this is my forms.py

class PostForm(forms.ModelForm):
    body = forms.CharField(widget=Pa         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 20:17

    An easy way to achieve this without editing the form would be to change the verbose_name on the model. For the video field on your model you could change the label on the form from "video" to "embed" like so:

    class Post(models.Model)
        video = models.UrlField(verbose_name="embed")
        # Other fields
    

提交回复
热议问题