Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /?date_from_day=8&date_from_month=5&date_from_year=1960&date_to_day=11&date_to_month=8&date_to_year=2018
- ?0=d&1=a&2=t&3=e&4=_&5=f&6=r&7=o&8=m&9=_&10=d&11=a&12=y&13=%3D&14=8....
- ?date_from_day=8
- class FilteredProductsListAPIView(LoginRequiredMixin, ListAPIView):
- authentication_classes = (authentication.SessionAuthentication,)
- permission_classes = (permissions.IsAuthenticated,)
- queryset = Product.objects.all()
- serializer_class = ProductSerializer
- filter_backends = (filters.DjangoFilterBackend,)
- filterset_class = ProductFilter
- def get_queryset(self):
- qs = Product.objects.filter(user=self.request.user).order_by("-timestamp")
- date_from_day = self.request.query_params.get("date_from_day", None)
- date_from_month = self.request.query_params.get("date_from_month", None)
- date_from_year = self.request.query_params.get("date_from_year", None)
- if date_from_day and date_from_month and date_from_year:
- date_from = datetime.date(int(date_from_year), int(date_from_month), int(date_from_day))
- qs = qs.filter(date__gte=date_from)
- # some more ugly code
- return qs
- def list(self, request, *args, **kwargs):
- queryset = self.get_queryset()
- total_count = queryset.count()
- draw = int(self.request.GET["draw"], 0)
- start = int(self.request.GET["start"], 0)
- length = int(self.request.GET["length"], 0)
- queryset = queryset[start:start+length]
- serializer = ProductSerializer(queryset, many=True)
- result = {"draw": draw,
- "recordsTotal": total_count,
- "recordsFiltered": total_count,
- "data": serializer.data}
- print("result:", result)
- return Response(result)
- url(r"^my-filtered-products/",
- views.FilteredProductsListAPIView.as_view(), name="filter-products"),
- <table class="table table-striped table-sm table-bordered" id="exampleAjax3">
- <thead>
- <tr>
- <th></th>
- <th>Date</th>
- <th>Time</th>
- <th>Title</th>
- <th>Description</th>
- <th>Price</th>
- <th></th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- function applyFilters(event) {
- event.preventDefault();
- var productFiltersForm = $(".my-product-filters-form");
- $('#exampleAjax3').dataTable( {
- "autoWidth": true,
- "displayLength": 10,
- "lengthChange": false,
- "ordering": false,
- "processing": false, // Show/Hide Processing message
- "searching": false,
- "serverSide": true,
- "language": {
- "zeroRecords": "Nothing to display",
- "info": "Showing _START_ to _END_ of _TOTAL_ products",
- "infoEmpty": ""
- },
- "ajax": {
- "processing": false, // Show/Hide Processing message
- "type": 'GET',
- "url": '/my-filtered-products/',
- "data": $(".my-product-filters-form").serialize(),
- "dataSrc": "data"
- },
- "columns": [
- { "data": "date" },
- { "data": "time" },
- { "data": "description" },
- { "data": "price" }],
- retrieve: true
- });
- }
- date_from_day=8&date_from_month=5&date_from_year=1960&date_to_day=11&date_to_month=8&date_to_year=2018&odds_from=1.100&odds_to=10.000&stake_from=1.000&stake_to=234.340&sport_multi=4
- /?date_from_day=8&date_from_month=5&date_from_year=1960&date_to_day=11&date_to_month=8&date_to_year=2018,
Add Comment
Please, Sign In to add comment