I am having a problem with my DRF API. I want to provide a read only endpoint that takes a single id from a object(document) in the DB and runs a script to perform an check and gives back the result. It works fine when I call the API with //api/documentcheck/1/ where 1 is the pk of the document in the DB. The problem is that if I just call the base URL //api/documentcheck/ it tries to give back the results of all documents in the database and times out because it takes ages.
I am looking for a way to remove the list view and force users to provide the ID for a single document to check.
This is my serializer class
class DocumentCheckSerializer(serializers.Serializer):
'''Serializer for document check'''
class Meta:
model = Document
fields = '__all__'
def to_representation(self, value):
return process_document(value)
This is my view:
class DocumentCheck(viewsets.ReadOnlyModelViewSet):
"""Check a single document"""
authentication_classes = (
TokenAuthentication,
SessionAuthentication,
BasicAuthentication,
)
permission_classes = [IsAuthenticated]
queryset = Document.objects.all()
serializer_class = serializers.DocumentCheckSerializer
and my router entry
router.register("documentcheck", views.DocumentCheck, basename="documentcheck")
listand return 404