Hi, (sorry for ma y poor english) i create my first aplication with Django DRF. it's works \o/ ;)
but now i want filter my datatable. DRF it's very good, but for me it's a little obcur. url of my application is : localhost:8000/paticuliers*/Millau* i dont understand how i can filter with argugument in red in my url in my url.py from django.conf.urls import include, url from django.contrib import admin #from django.urls import path from rest_framework.routers import DefaultRouter from distrisac.views import ParticulierViewSet, EntrepriseViewSet, index, app_particuliers, app_entreprises router = DefaultRouter() router.register(r'particuliers', ParticulierViewSet) router.register(r'entreprises', EntrepriseViewSet) urlpatterns = [ url(r'^index/', index), #url(r'^particuliers/', app_particuliers), url(r'^particuliers/(?P<ville>.+)/$', app_particuliers), url(r'^entreprises/', app_entreprises), url('admin/', admin.site.urls), url(r'^api/', include(router.urls)), ] my models.py .. from __future__ import unicode_literals from django.db import models from django.db.models import Q from model_utils import Choice ... ... class particuliers(models.Model): pk_particulier = models.AutoField(primary_key=True) foyer = models.CharField(max_length=255,null=True) numero_immeuble = models.CharField(max_length=10,null=True) indice_repetition_numero_immeuble = models.CharField(max_length=10,null= True) libelle_voie = models.TextField(null=True) code_postal = models.CharField(max_length=10,null=True) ville = models.CharField(max_length=50,null=True) ... class Meta: db_table = "distrisac_particuliers" def query_particuliers_by_args(**kwargs): draw = int(kwargs.get('draw', None)[0]) length = int(kwargs.get('length', None)[0]) start = int(kwargs.get('start', None)[0]) search_value = kwargs.get('search[value]', None)[0] order_column = kwargs.get('order[0][column]', None)[0] order = kwargs.get('order[0][dir]', None)[0] order_column = ORDER_COLUMN_CHOICES[order_column] # django orm '-' -> desc if order == 'desc': order_column = '-' + order_column queryset = particuliers.objects.all() total = queryset.count() if search_value: queryset = queryset.filter(Q(pk_particulier__icontains=search_value) | Q(foyer__icontains=search_value) | Q(libelle_voie__icontains= search_value)) count = queryset.count() queryset = queryset.order_by(order_column)[start:start + length] return { 'items': queryset, 'count': count, 'total': total, 'draw': draw } and in my view.py from django.shortcuts import render from distrisac.models import particuliers from distrisac.serializers import ParticuliersSerializer ... ... # Create your views here. from rest_framework import viewsets, status from rest_framework.response import Response from rest_framework import generics from django.template.response import TemplateResponse from django.http.response import HttpResponse from distrisac.models import query_particuliers_by_args from django.views.generic import TemplateView from django_datatables_view.base_datatable_view import BaseDatatableView def index(request): html = TemplateResponse(request, 'index.html') return HttpResponse(html.render()) def app_particuliers(request,**kwargs): html = TemplateResponse(request, 'particuliers.html') return HttpResponse(html.render()) ... ... # Create your views here. class ParticulierViewSet(generics.ListCreateAPIView): #viewsets.ModelViewSet): queryset = particuliers.objects.all() filter_fields = ('ville',) serializer_class = ParticuliersSerializer def get_queryset(self): return self.queryset.filter(ville=self.kwargs.get('ville')) def list(self, request, **kwargs): try: distrisac = query_particuliers_by_args(**request.query_params) serializer = ParticuliersSerializer(distrisac['items'], many= True) result = dict() result['data'] = serializer.data result['draw'] = distrisac['draw'] result['recordsTotal'] = distrisac['total'] result['recordsFiltered'] = distrisac['count'] return Response(result, status=status.HTTP_200_OK, template_name =None, content_type=None) except Exception as e: return Response(e, status=status.HTTP_404_NOT_FOUND, template_name=None, content_type=None) in my console i have this error : typeError : as_view() takes 1 positionnal argument but 2 were given someone ca me help please ? Thanks a lot Christophe -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.