from rest_framework import fields, serializers, views
class QueryParamsParser(serializers.Serializer):
intarg = fields.IntegerField()
boolarg = fields.BooleanField()
class View(views.APIView):
def get(request):
query_params = QueryParamsParser(data=request.query_params)
...
Note that default BooleanField instances will be generated with a required=False option (since Django models.BooleanField is always blank=True). If you want to change this behaviour explicitly declare the BooleanField on the serializer class.что имеется ввиду под объявлением поля прямо в классе сериализатора, я так и не вкурил.
class DayPlanViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
serializer_class = DayPlanSerializer
filter_backends = (filters.SearchFilter, DjangoFilterBackend,)
filter_fields = ('user',)
def get_queryset(self):
if self.request.GET.get('start'):
return DayPlan.objects.filter(start__contains=self.request.GET['start']).order_by('-start')
return 'error: miss parameters'