Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ProductSearchForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super(ProductSearchForm, self).__init__(*args, **kwargs)
- self.fields['length_range'].empty_label = "any size"
- self.fields['hull_type'].empty_label = "any type"
- self.fields['power'].empty_label = "any type"
- self.fields['speed'].empty_label = "any speed"
- self.fields['hull_only_available'].empty_label = None
- # self.fields['price'].widget.attrs['min'] = Product.price
- # self.fields['price'].widget.attrs['max'] = Product.price
- class Meta:
- model = Product
- fields = ('length_range', 'hull_type', 'price', 'power', 'speed', 'hull_only_available')
- class IndexView(FormView):
- template_name = 'index.html'
- form_class = ProductSearchForm
- success_url = "search/"
- def get_context_data(self, **kwargs):
- context = super(IndexView, self).get_context_data(**kwargs)
- context['length_ranges'] = LengthRange.objects.all().order_by('pk')
- context['hull_types'] = Hull.objects.all().order_by('pk')
- context['power_configs'] = PowerConfiguration.objects.all().order_by('pk')
- context['speed_ranges'] = SpeedRange.objects.all().order_by('pk')
- context['price'] = Product.objects.all().aggregate(Min('price'), Max('price'))
- return context
- def get_form_kwargs(self):
- kwargs = super(IndexView, self).get_form_kwargs()
- print(kwargs)
- return kwargs
- <form class="nl-form" action="{% url 'boatsales:search' %}" method="get">
- A boat with a length of
- {{ form.length_range }}
- , with hull type of
- {{ form.hull_type }}
- with
- {{ form.power }}
- power
- configuration and a top speed between
- {{ form.speed }}.
- My budget is from $<input type="text" value="{{ price.price__min|intcomma }}"
- placeholder="{{ price.price__min|intcomma }}"
- data-subline="Our current lowest price is: <em>{{ price__min|intcomma }}</em>"/>
- to
- $<input
- type="text" value="{{ price.price__max|intcomma }}"
- placeholder="{{ price.price__min|intcomma }}"
- data-subline="Our current highest price is: <em>{{ price.price__min|intcomma }}</em>"/>.
- Hull only
- availability <select>
- <option value="False" selected>is not</option>
- <option value="True">is</option>
- </select> a concern.
- <div class="container">
- <button type="submit"
- class="btn-a btn-a_size_large btn-a_color_theme">
- Show me the results!
- </button>
- </div>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement