myModelViewSet.py 780 Bytes
Newer Older
1
from .myModelSerializer import MyModelSerializer
Florent Chehab's avatar
Florent Chehab committed
2 3
from backend_app.permissions import DEFAULT_VIEWSET_PERMISSIONS
from backend_app.custom import DictModeViewSet
4 5


6
class MyModelViewSet(DictModeViewSet):
7
    serializer_class = MyModelSerializer
8
    permission_classes = DEFAULT_VIEWSET_PERMISSIONS
9 10 11 12 13 14

    def get_queryset(self):
        """
        Extended default rest framework behavior
        to prefetch some table and enhance performances
        """
15
        self.my_model_queryset = self.queryset.prefetch_related(
16 17
            "moderated_by", "updated_by", "pending_moderation"
        )
18 19 20 21 22 23
        return self.extend_queryset()

    def extend_queryset(self):
        """
        Function to extend get_queryset when subclassing
        """
24
        return self.my_model_queryset