1
votes

I've a dropdown menu in my template and I'm trying to store the selection made by user to filter the doctor objects. But I keep getting this error:

Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
  57.         return view_func(*args, **kwargs)
File "views.py" in doclistings
  91.     if request.session.get["selection"] == "Dentist":

Exception Type: TypeError at /doclistings/
Exception Value: 'instancemethod' object has no attribute '__getitem__'

here is the index template

<div class="signup">
          <div class="form-group">
            <form action="/doclistings/" method="get" >
            <select class="form-control" id="selection" name="selection">
              <option><b>Find a Doctor...</b></option>
              {% for value, text in form.selection.field.choices %}
                <option value="{{ value }}">{{ text }}</option>
              {% endfor %}
              {% csrf_token %}
            </select>

here is the doclisting views where I'm trying to filter based on the selection

def doclistings(request):
    d = getVariables(request)
    doctors = Doctor.objects.all().order_by('-likes')
    paginator = Paginator(doctors, 20) #Show 20 doctors per page
    page =  page = request.GET.get('page')
    # print request.session["selection"]
    # print request.session.get("selection", None)

    if request.session.get["selection"] == "Dentist":
        doctors = Doctor.objects.filter(specialization = "Dentist").order_by('-likes')

    try:
        doctors = paginator.page(page)
    except PageNotAnInteger:
        doctors = paginator.page(1)
    except EmptyPage:
        doctors = paginator.page(paginator.num_pages)
    d['doctors'] = doctors
    d['paginator'] = paginator

    return render_to_response('meddy1/doclistings.html',d)

The doctor model has a specialisation attribute and I'm trying to filter the doctors based on user selection.

1

1 Answers

4
votes

get is a method

request.session.get('selection')