Skip to content

Commit

Permalink
Prefetch Serialization: Add a preference during mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Maffooch committed Sep 18, 2024
1 parent a643544 commit e50107e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dojo/api_v2/prefetch/prefetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@

from rest_framework.serializers import ModelSerializer

from dojo.models import FileUpload

from . import utils

# Reduce the scope of search for serializers.
SERIALIZER_DEFS_MODULE = "dojo.api_v2.serializers"

preferred_serializers = {
FileUpload: "FileSerializer",
}


class _Prefetcher:
@staticmethod
Expand All @@ -31,7 +37,11 @@ def _is_model_serializer(obj):

for _, serializer in available_serializers:
model = serializer.Meta.model
serializers[model] = serializer
if model in preferred_serializers:
if serializer.__name__ == preferred_serializers[model]:
serializers[model] = serializer
else:
serializers[model] = serializer
# We add object->None to have a more uniform processing later on
serializers[object] = None

Expand Down

0 comments on commit e50107e

Please sign in to comment.