form中使用widget的例子

 https://docs.djangoproject.com/en/4.2/ref/forms/widgets/

所有的widget

 

class Item(models.Model):

    YEAR_CHOICES = (
        (10, '10代'),
        (20, '20代'),
        (30, '30代'),
        (40, '40代'),
    )

    age = models.IntegerField(verbose_name="年齢", choices=YEAR_CHOICES)

默认时下拉:

 

 

class ItemForm(forms.ModelForm):


    class Meta:
        model = Item
        fields = ("__all__")
        widgets = {
                    "name": forms.TextInput(attrs={'placeholder':'紀伊 太郎'}),
                    "age": forms.RadioSelect(),

                  }

改成radio

 

posted @ 2023-09-01 16:19  花生与酒  阅读(53)  评论(0编辑  收藏  举报