Django模型形式选择

时间:2018-12-19 09:42:53

标签: django django-forms django-views

我正在使用Django 2.1.3,并且在使用“组合框”时遇到了一些麻烦。 我有一个包含所有字段的模型,并将它们传递给表单,但是当我看到页面时,所有选择字段的字段均未显示。 我在做什么错了?

models.py

webView.scrollView.contentOffset = CGPoint(x: 0, y: offset)

forms.py

class nconfm(models.Model):
NAT_CHOICES = (
        ('NCI', 'NC Interna'),
        ('NCF', 'NC Fornecedor'),
        ('OS', 'Outra Situação'),
        ('OPM', 'Oportunidade / Melhoria'),
    )
data = models.DateField()
natureza = models.CharField(max_length=50, choices=NAT_CHOICES)

index.html

class data(forms.DateInput):
  format_key = 'DATE_INPUT_FORMATS'
  input_type = 'date'
class formnconf(forms.ModelForm):
  class Meta:
    model = nconfm
    fields = ['data','natureza']
    widgets = {
        'data': data(),
    }

views.py

<form class="site-form" action="" method='POST'>
      {% csrf_token %}
      {{form}}
</form>

已修复,这是CSS配置中的问题

1 个答案:

答案 0 :(得分:-1)

编辑: 您的模型:

class nconfm(models.Model):
  data = models.DateField()
  natureza = models.CharField(max_length=50)

您的forms.py:

class formnconf(forms.ModelForm):
  NAT_CHOICES = (
    ('NCI', 'NC Interna'),
    ('NCF', 'NC Fornecedor'),
    ('OS', 'Outra Situação'),
    ('OPM', 'Oportunidade / Melhoria'),
)
  data = forms.DateField(widget=forms.SelectDateWidget())
  natureza = forms.ChoiceField(choices = NAT_CHOICES, widget= forms.Select())
  class Meta:
    model = nconfm
    fields = ['data','natureza']