запросах в рестапи.
Запрос - api/appointments?start_date=2018/08/30&end_date=2018/09/30
Реализация -
class AppointmentsItemFilter(FilterSet):
start_date = DateFilter(name='start_datetime',lookup_type=('gt'),)
end_date = DateFilter(name='start_datetime',lookup_type=('lt'))
class Meta:
model = Appointments
fields = ['start_datetime',]
class AppointmentsViewSet(viewsets.ModelViewSet):
permission_classes = (IsLoggedPermission, permissions.IsAuthenticated)
queryset = Appointments.objects.all()
serializer_class = AppointmentsSerializer
filter_class = AppointmentsItemFilter
#filter_backends = (DjangoFilterBackend, )
#filter_fields = ('id', 'patient')
def __str__(self):
return "Записи"
def list(self, request):
# Note the use of `get_queryset()` instead of `self.queryset`
if(self.request.user.profile.doctor):
queryset = self.get_queryset().filter(appointedServicesExecutions__doctor = self.request.user.profile.doctor)
else:
if(self.request.user.is_superuser):
queryset = self.get_queryset()
serializer = AppointmentsSerializer(queryset, many=True)
return Response(serializer.data)
- но что-то не работает. ('start_datetime' - есть в сериализаторе в списке полей, и в классе Appointments)
ты лучше AppointmentsItemFilter покажи
Обсуждают сегодня