python - Django Filtering Search Results using GET -


i build filter listview, further narrow down search results.

currently, user searches services in area , chooses between paid or free service (using radio buttons).

forms.py

class locationform(forms.form):     place = forms.charfield(label='place')     lat = forms.floatfield()     lng = forms.floatfield()     choices = [('free', 'paid'),                ('free', 'paid')]     type = forms.choicefield(choices=choices, widget=forms.radioselect())     searchradius = forms.integerfield() 

views.py

def get_context_data(self, **kwargs):     if self.request.method == 'get':         form = locationform(self.request.get)         if form.is_valid():             searchpoint=point(form.cleaned_data['lng'],form.cleaned_data['lat'])             radius = form.cleaned_data['searchradius']             type = form.cleaned_data['type']         else:             form = locationform()             searchpoint=point(0,0)             radius = 15             type='free'         try:             type         except:             vt_filter = "'free'=true"         else:             if type == 'free':                 vt_filter="'free'=true"             else:                 vt_filter="'paid'=true"        context = super(indexview, self).get_context_data(**kwargs)      res = model.objects.filter(location__distance_lte=                                  (searchpoint, d(km=radius)),vt_filter)\         .annotate(distance=distance('location', searchpoint))\         .order_by('distance')      context['model_list'] = res     context['form'] = form      return context 

i wanted add similar .filter('free'=true) further narrow down results.

in models.py, model, have boolean fields free , paid respectively.

free = models.booleanfield(default=true) paid = models.booleanfield(default=false) 

it seems vt_filter, additional filter want run distinguish between free , paid services doesn't work, , gives me error: many values unpack (expected 2)


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -