I have successfully configured a way to upload files to a website that I am making. However we would like to include a drop-down menu on the site. However, we want to include in the form of a drop-down menu called "mismatch choice":
models.py: for drop-down menu
class Mismatches(models.Model):
MISMATCH_CHOICES = (
('0', '0'),
('1', '1'),
('2', '2'),
('3', '3'),
)
mismatch = models.IntegerField(max_length=1, default='0', choices = MISMATCH_CHOICES)
forms.py for drop-down menu:
class MismatchesForm(ModelForm): #unsure how to reference a class in our in-app-urls.py
class Meta:
model = Mismatches
fields = ['mismatch']
'model=Mismatches' links to the Mismatches class in models and the 'field' gives the options.
views.py for drop-down menu
class Mismatch_Choice(FormView):
template_name = 'list.html'
form_class = MismatchesForm
"template_name = 'list.html'" links the html page called list.html. 'form_class' links to the form 'MismatchesForm'.
html for drop-down menu
<form action="" method="post">{% csrf_token %}
{{ form.mismatch }}
<input type="submit" value="Submit" />
</form>
We used a tutorial as a template for our code but it won't display on our html page even though we have referenced it with {{ form.mismatch}} which links to the variable 'mismatch' which is set in our form as the 'model' and hence links to the options given in models.py.
We are wondering if the html page is not seeing the drop-down menu because it's set as a class in the forms.py but we haven't referenced a class in our in-app urls.py (is there a way to do this?)...
NOTE: all migrations were accordingly applied and the server was restarted multiple times