小编Hug*_*oya的帖子

如何使用表单中在模型中声明的choiceField。詹戈

我有这个 model.py

class marca(models.Model):
    marcas = (
        ('chevrolet', 'Chevrolet'),
        ('mazda', 'Mazda'),
        ('nissan', 'Nissan'),
        ('toyota', 'Toyota'),
        ('mitsubishi', 'Mitsubishi'),
    )

    marca = models.CharField(max_length=2, choices= marcas)
    def __unicode__(self):
        return self.marca
Run Code Online (Sandbox Code Playgroud)

我需要在form.py 尝试使用它的过程中使用它,但是它不起作用。

class addVehiculoForm(forms.Form):
    placa                   = forms.CharField(widget = forms.TextInput())
    tipo                    = forms.CharField(max_length=2, widget=forms.Select(choices= tipos_vehiculo))
    marca                   = forms.CharField(max_length=2, widget=forms.Select(choices= marcas))
Run Code Online (Sandbox Code Playgroud)

django django-models django-forms choicefield

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

choicefield ×1

django ×1

django-forms ×1

django-models ×1