Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. class ProductSearchForm(forms.ModelForm):
  2.  
  3. def __init__(self, *args, **kwargs):
  4. super(ProductSearchForm, self).__init__(*args, **kwargs)
  5. self.fields['length_range'].empty_label = "any size"
  6. self.fields['hull_type'].empty_label = "any type"
  7. self.fields['power'].empty_label = "any type"
  8. self.fields['speed'].empty_label = "any speed"
  9. self.fields['hull_only_available'].empty_label = None
  10. # self.fields['price'].widget.attrs['min'] = Product.price
  11. # self.fields['price'].widget.attrs['max'] = Product.price
  12.  
  13. class Meta:
  14. model = Product
  15. fields = ('length_range', 'hull_type', 'price', 'power', 'speed', 'hull_only_available')
  16.  
  17. class IndexView(FormView):
  18. template_name = 'index.html'
  19. form_class = ProductSearchForm
  20. success_url = "search/"
  21.  
  22. def get_context_data(self, **kwargs):
  23. context = super(IndexView, self).get_context_data(**kwargs)
  24. context['length_ranges'] = LengthRange.objects.all().order_by('pk')
  25. context['hull_types'] = Hull.objects.all().order_by('pk')
  26. context['power_configs'] = PowerConfiguration.objects.all().order_by('pk')
  27. context['speed_ranges'] = SpeedRange.objects.all().order_by('pk')
  28. context['price'] = Product.objects.all().aggregate(Min('price'), Max('price'))
  29. return context
  30.  
  31. def get_form_kwargs(self):
  32. kwargs = super(IndexView, self).get_form_kwargs()
  33. print(kwargs)
  34. return kwargs
  35.  
  36. <form class="nl-form" action="{% url 'boatsales:search' %}" method="get">
  37. A boat with a length of
  38. {{ form.length_range }}
  39. , with hull type of
  40. {{ form.hull_type }}
  41. with
  42. {{ form.power }}
  43. power
  44. configuration and a top speed between
  45. {{ form.speed }}.
  46. My budget is from $<input type="text" value="{{ price.price__min|intcomma }}"
  47. placeholder="{{ price.price__min|intcomma }}"
  48. data-subline="Our current lowest price is: <em>{{ price__min|intcomma }}</em>"/>
  49. to
  50. $<input
  51. type="text" value="{{ price.price__max|intcomma }}"
  52. placeholder="{{ price.price__min|intcomma }}"
  53. data-subline="Our current highest price is: <em>{{ price.price__min|intcomma }}</em>"/>.
  54. Hull only
  55. availability <select>
  56. <option value="False" selected>is not</option>
  57. <option value="True">is</option>
  58. </select> a concern.
  59. <div class="container">
  60. <button type="submit"
  61. class="btn-a btn-a_size_large btn-a_color_theme">
  62. Show me the results!
  63. </button>
  64. </div>
  65. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement