2021年4月9日星期五

How to allow users to submit a get request to a class View and order item?

<form action="">      Sort By:      <select name="ordering">          <option value="price">Price:Highest to Lowest</option>          <option value="-price">Price:Lowest to Highest</option>      </select>      <button type="submit">submit</button>  <form>  

trying to submit these values in a get request. Tried doing a get_ordering function on a class List View:

class GarageListView(ListView):      model = Vehicles      template_name = 'garage/garage.html'      context_object_name = 'cars'      ordering = ['-price']          def get_context_data(self, **kwargs):          context = super().get_context_data(**kwargs)            context['filter'] = VehicleFilter(              self.request.GET, queryset=self.get_queryset())          return context          def get_ordering(self):              self.ordering = self.request.GET.get('ordering','-price')              return self.ordering  

When users select and submit any sort option, it should refresh the page and sort by value

https://stackoverflow.com/questions/67030693/how-to-allow-users-to-submit-a-get-request-to-a-class-view-and-order-item April 10, 2021 at 12:05PM

没有评论:

发表评论