urls.py
url(r'^search?(?P<pt>\w+)&(?P<nb>\w+)&(?P<nw>\w+)', views.IndexSearchResults.as_view(), name='search-results')
index.html
<form action="{% url 'search-results' pt=property_type nb=number_of_bedrooms nw=number_of_washrooms %}" method="get">
{{ form.as_p }}
</form>
views.py
class IndexSearchResults(generic.ListView):
template_name = 'search-results.html'
models.py
Class BuyerListing(models.Model):
BEDS_OPTION = (
(BEDS_0, '0 [Studio/Bachelor]'),
(BEDS_1, '1'),
(BEDS_1_1, '1+1'),
(BEDS_2, '2'),
(BEDS_2_1, '2+1'),
(BEDS_3, '3'),
(BEDS_3_1, '3+1'),
(BEDS_4, '4'),
(BEDS_5, '5'),
(BEDS_5_1, '5+'),
)
WASH_OPTION = (
(WASH_1, '1'),
(WASH_2, '2'),
(WASH_3, '3'),
(WASH_4, '4'),
(WASH_5, '5'),
(WASH_5_1, '5+'),
)
PROPERTY_TYPE = (
(CONDO_APARTMENT, 'Condo Apartment'),
(DETACHED_HOUSE, 'Detached House'),
(SEMI_DETACHED, 'Semi-detached'),
(TOWNHOUSE, 'Townhouse'),
)
property_type = models.CharField(max_length=50)
number_of_bedrooms = models.CharField(max_length=50, default=BEDS_0)
number_of_washrooms = models.CharField(max_length=50, default=WASH_1)
forms.py
class MainSearch(forms.Form):
property_type = forms.ChoiceField(choices=BuyerListing.PROPERTY_TYPE)
number_of_bedrooms = forms.ChoiceField(choices=BuyerListing.BEDS_OPTION)
number_of_washrooms = forms.ChoiceField(choices=BuyerListing.WASH_OPTION)