django: drop down menu not displaying on template despite correct syntax

2016-02-16 Thread clarksonchris81


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

{% csrf_token %}

  {{ form.mismatch }}

  




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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7785168-32ed-4a42-8406-291ca8140051%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django: drop down menu not displaying on template despite correct syntax

2016-02-17 Thread jorrit787
Have you tried using just {{ form }} instead of {{ form.mismatch }} ?

Also, (not sure if this is related) in your MISMATCH_CHOICES tuple you are 
giving strings instead of integers for the key value. Try using (0, '0') 
instead of ('0','0')


On Tuesday, February 16, 2016 at 2:16:17 PM UTC+1, clarkso...@gmail.com 
wrote:
>
> 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
>
> {% csrf_token %}
>
>   {{ form.mismatch }}
>
>   
>
> 
>
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dab775e8-7d3a-4140-b9ed-f4b16cef8b35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.