Reputation: 4460
I am trying to do with ModelViewSet. I am facing this error now
Here is my viewset=>
class ShiftViewSet(viewsets.ModelViewSet):
queryset = Shift.objects.all()
serializer_class = ShiftSerializer()
# filter_backends = (filters.DjangoFilterBackend,)
# filterset_fields = ('shiftid',)
@action(methods=['get'], detail=False)
def newest(self, request):
newest = self.get_queryset().order_by('Created_DT').last()
serializer = self.get_serializer_class()(newest)
return Response(serializer.data)
@action(methods=['get'], detail=False)
def shiftsum(self, request):
query = (
Shift.objects.values('shiftid')
.annotate(shiftdesc=Max('shiftdesc'))
.annotate(overnight=Max('overnight'))
.annotate(isspecialshift=Max('isspecialshift'))
.annotate(ct=Count('*')) # get count of rows in group
.order_by('shiftid')
.distinct()
)
serializer = ShiftSummarySerializer(query,many=True)
return Response(serializer.data)
@action(methods=['get'], detail=False)
def byshiftid(self, request):
shiftid = self.request.query_params.get('shiftid',None)
query = self.get_queryset().filter(shiftid=shiftid)
serializer = ShiftSerializer(query,many=True)
return Response(serializer.data)
Here is my router and url =>
router.register('shifts_mas', ShiftViewSet, base_name='shifts')
path('api/', include(router.urls))
Normally I can call like /api/shifts_mas/ and I will get all record of shift
but just now i got this error and i dont know why. May i know why?
Upvotes: 0
Views: 228
Reputation: 32304
You should have a serializer class and not an instance of the class as your serializer_class
attribute
serializer_class = ShiftSerializer # No parenthesis here
Upvotes: 2