I am trying to pass data from a form to view, but form is not valid.

I have 3 drop-downs on this form on clicking on submit, if any relavant 
data is available in the database it should be loaded on the template. 
Basically this form is a set of filters that load data based on selection.

views.py

def mentioe(request):
emp_dd= request.user.username
flag=0if request.method == 'POST':
    form = Management_Collector(request.POST or None)
    if form.is_valid():
        m_s = form.cleaned_data.get('month_start')
        m_e = form.cleaned_data.get('month_end')
        y = form.cleaned_data.get('process_select')

        mentione= mrg_bpo.objects.filter(Q(emp_id=emp_dd) & Q(month=m_s))

        if not mentione:
            messages.error(request, 'Data is not available for your selection 
please consider re-selecting.')
        else:
            messages.success(request, 'Search Result Displayed Below')
        return render(request, 'mentione.html', {'form': form, 'mentione': 
mentione})
    else:
        print(form.errors)
        print('some issue')

else:
    print('i go to else')
    form = Management_Collector()return render(request, 'mentione.html', 
{'form': form})

forms.py class Management_Collector(forms.ModelForm):

class Meta:
    model = mrg_bpo
    fields = ['month','year','process_select']
    labels = {
        "month": _(""),
    }
    widget = {
        'month':forms.HiddenInput(),
        'year':forms.HiddenInput(),
    }

index.html

<form action="" method="POST">

                    {%csrf_token%}<select class="form-control" id="month_start" 
name="month_start">

  {% for i in form.month %}<option>{{ i }}</option>
{% endfor %}</select>

<select class="form-control" id="month_end" name="month_end" > <option>
</option>
 {% for i in form.month %}<option>{{ i }}</option>
        {% endfor %}
         </select>

{{form.year}}
{{form.process_select}}
 <button type="submit" class="btn btn-success" id="btn">Submit</button></form>

I want to get the value of all the drop downs in my view

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/cb4599dd-d98f-4331-b7ae-56be77acb335%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to