myModelViewSet.py 763 Bytes
Newer Older
1
from .myModelSerializer import MyModelSerializer
2
from backend.permissions import DEFAULT_VIEWSET_PERMISSIONS
3
from backend.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(
Florent Chehab's avatar
Florent Chehab committed
16
            'moderated_by', 'updated_by', 'pending_moderation')
17
18
19
20
21
22
        return self.extend_queryset()

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