def units(self, request, **kwargs): obj = self.get_object() if request.method == "POST": if not request.user.has_perm("unit.add", obj): self.permission_denied(request, "Can not add unit") serializer = MonolingualUnitSerializer(data=request.data) serializer.is_valid(raise_exception=True) key = serializer.validated_data["key"] value = serializer.validated_data["value"] if obj.unit_set.filter(context=key).exists(): raise ValidationError( "Translation with this key seem to already exist!" ) obj.new_unit(request, key, value) serializer = self.serializer_class(obj, context={"request": request}) return Response(serializer.data, status=HTTP_200_OK) queryset = obj.unit_set.all().order_by("id") page = self.paginate_queryset(queryset) serializer = UnitSerializer(page, many=True, context={"request": request}) return self.get_paginated_response(serializer.data)
def units(self, request, **kwargs): obj = self.get_object() queryset = obj.unit_set.all().order_by("id") page = self.paginate_queryset(queryset) serializer = UnitSerializer(page, many=True, context={"request": request}) return self.get_paginated_response(serializer.data)