0

I have a form say like this:

class ContributorSearchForm(forms.Form):
    space = forms.ChoiceField(widget = forms.Select())
    sub_category = forms.ChoiceField(widget = forms.Select(), required=False)
    style = forms.ChoiceField(widget=forms.Select(), required=False)
    colour = forms.ChoiceField(widget=forms.Select(), required=False)
    material_type = forms.ChoiceField(widget=forms.Select(), required=False)

I am required to have urls like this:

www.myabc.com/space-<spacevalue>/subcategory-<sub-category-value>/style-<style-value>/colour<colour-value>/material-<material-value>

when someone searches for space, sub-category or any number of combinations possible, like someone only searchs with space and colour, space and style.. etc ? can it be attained with a single url ?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
vijay shanker
  • 2,517
  • 1
  • 24
  • 37
  • 1
    are you looking for this [http://stackoverflow.com/questions/14351048/django-optional-url-parameters] – lima Feb 07 '14 at 09:20

1 Answers1

0

The URL you specify makes no sense for a search - the way it is structured for displaying subitems, i.e. a color that is in a subcategory that is in a space, not search querys. If this is a requirement fromt he client, explain to the client how URL's should be structured.

I would suggest using GET paremeters for it, like the following:

www.myabc.com/?space=<spacevalue>&subcategory=<sub-category-value>&style=<style-value>&colour=<colour-value>&material=<material-value>

In your view you collect the search params:

space_filter = request.GET.get('space', None)
subcategory_filter = request.GET.get('subcategory', None)
style_filter = request.GET.get('style', None)
colour_filter = request.GET.get('colour', None)
material_filter = request.GET.get('material', None)
cvitan
  • 61
  • 1
  • 3