Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you want either of these:</p> <pre><code>OrderFormSet = SearchOrderForm() if OrderFormSet.is_valid(): formset = SearchOrderForm() if formset.is_valid() </code></pre> <p>With the second way being the preferred syntax style. As a matter of nitpicking, Django offers a FormSet type which is different than the Form type so it is convention to refer to instances of Forms as "form":</p> <pre><code>form = SearchOrderForm() if form.is_valid(): </code></pre> <p>You are going to have some other problems with your code:</p> <pre><code>def order_status(request): error = False error_searching = False if request.method == 'POST': #instead of: #OrderFormSet = SearchOrderForm() #formset = OrderFormSet() #instantiate an instance of your ModelForm #(I'd normally name it "form") formset = SearchOrderForm() if formset.is_valid(): cd = formset.cleaned_data() #cd is now a Python dictionary #these next 2 lines don't make sense, what is your intention? emodels_results = cd() emodels_results = cd(queryset = Order.objects.filter(Q(patient_first_name=search)|Q(patient_last_name=search)|Q(client_id=search))) #you've already used your form to process and clean #the incoming POST data. use the cleaned data instead #patient_first_name = request.POST('patient_first_name', None) patient_first_name = cd.get('patient_first_name','') #use data from the form's cleaned_data as in the line above #I'm not sure what your intention is with how the emodels_results #is but you'll need to rework that for it all to work if patient_first_name: emodels_results = emodels_results(queryset = Order.objects.filter(patient_first_name=patient_first_name)) patient_last_name = request.POST('patient_last_name', None) if patient_last_name: emodels_results = emodels_results(queryset = Order.objects.filter(patient_last_name=patient_last_name)) client_id = request.POST('client_id', None) if client_id: emodels_results = emodels_results(queryset = Order.objects.filter(client_id=client_id)) return render_to_response('search_results.html', {'models': emodels_results}) else: emodels_results = "Still messed up!" return render_to_response('search_results.html', {'models': emodels_results}) else: error_searching = True form = SearchOrderForm() return render_to_response('order_status.html', {'form': form, 'error': error, 'error_searching': error_searching}) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload