Features: 1) Add get_queryset method to BrandViewSet for conditional prefetching of categories.
Fixes: 1) Add missing import for `Prefetch` in `core/viewsets.py`. Extra: n/a.
This commit is contained in:
parent
1563016af0
commit
a4e4e3cd40
1 changed files with 14 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import uuid
|
||||
from uuid import UUID
|
||||
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Prefetch
|
||||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.decorators import method_decorator
|
||||
|
|
@ -308,6 +308,19 @@ class BrandViewSet(EvibesViewSet):
|
|||
"list": BrandSimpleSerializer,
|
||||
}
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Brand.objects.all()
|
||||
|
||||
if self.request.user.has_perm("view_category"):
|
||||
queryset = queryset.prefetch_related("categories")
|
||||
else:
|
||||
queryset = queryset.prefetch_related(
|
||||
Prefetch("categories", queryset=Category.objects.filter(is_active=True))
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
|
||||
@extend_schema_view(**PRODUCT_SCHEMA)
|
||||
class ProductViewSet(EvibesViewSet):
|
||||
|
|
|
|||
Loading…
Reference in a new issue