creating django forms

后端 未结 3 1371
忘了有多久
忘了有多久 2020-12-23 15:03

I\'m struggling to get my head round django forms.. I\'ve been reading various documentation but just can\'t quite grasp the concepts. I have got to grips with models, views

3条回答
  •  独厮守ぢ
    2020-12-23 16:03

    Simply use CharField in your modelform as below:

    SIZES_CHOICES = (
        ('size1', 'M'),
        ('size2', 'L'),
    )
    size = models.CharField(max_length=100, choices=SIZES_CHOICES, default=size1)
    

    in the above code, size1 is the value which will be going to store in your database as name 'size1' and in the drop-down menu, there will be an option is 'M' of right side.you can mentioned any name to these options.

提交回复
热议问题