0

I am currently minutes away from throwing my monitor at the wall so if anybody could help me with this problem that would be great :) I have made a GET form which sends you to a different page, once the user has arrived at this page the view is suppose to take the GET parameters from the URL and then decide what content to display. However I am having trouble with what I think should be a simple if statement, the if statement is essentially suppose to check if they came to the page via the GET form by checking if all of the parameters are equal to None. But for some reason even if all the parameters are None it will not detect it. Can anyone see the problem?

View -

def browse(request):

    business_industry = request.GET.get('business_industry', None)
    business_address_region = request.GET.get('business_address_region', None)
    keywords = request.GET.get('keywords', None)
    print(business_industry)
    print(business_address_region)
    print(keywords)

    if business_industry and business_address_region and keywords is not None:
        print("If")
    else:
        print("Else")

    job_listings = JobListing.objects.exclude(active_listing=False)

    context_dict = {
        'joblistings': job_listings
    }

    return render(request, 'browse.html', context_dict)

Form -

region_choice = (
    (None, 'Region'),
    ('1', 'Auckland'),
    ('2', 'Wellington'),
    ('3', 'Christchurch')
)
suburb_choice = (
    (None, 'None'),
    ('1', 'Glendowie'),
    ('2', 'Kohimarama'),
    ('3', 'Herne Bay')
)
industry_choice = (
    (None, 'Business Industry'),
    ('1', 'Accounting'),
    ('2', 'Agriculture, fishing & forestry'),
    ('3', 'Automotive'),
    ('4', 'Banking, finance & insurance'),
    ('5', 'Construction & Architecture'),
    ('6', 'Customer service'),
)
employment_type_choice = (
    (None, 'None'),
    ('1', 'Full Time'),
    ('2', 'Part Time'),
    ('3', 'One-off'),
    ('4', 'Other')
)

class JobQuickSearchForm(forms.Form):
    business_address_region = forms.ChoiceField(region_choice, required=False, widget=forms.Select(attrs={'class': 'qs-form-input'}))
    business_industry = forms.ChoiceField(industry_choice, widget=forms.Select(attrs={'class': 'qs-form-input'}))
    keywords = forms.CharField(max_length=20, widget=forms.TextInput(attrs={'class': 'qs-form-input', 'placeholder': 'Enter Keywords...'}))

HTML -

  <div id="quicksearch">
    <h1 class="pageheader">Where would you to like to work?</h1>
      <form class="qs-form" action="{% url 'browse' %}">
        {{ form.non_field_errors }}
        {{ form.business_industry }}
        {{ form.business_address_region }}
        {{ form.keywords }}<br>
        <button type="submit" class="qs-form-button">Search Jobs</button>
      </form>
  </div>
eZ_Harry
  • 816
  • 9
  • 25

0 Answers0