celery & attributes list by product
This commit is contained in:
@@ -118,11 +118,26 @@ class ProductViewSet(viewsets.ModelViewSet):
|
||||
class AttributeViewSet(viewsets.ModelViewSet):
|
||||
""" attributes of reference product """ #
|
||||
|
||||
queryset = product_models.Attribute.objects.all()
|
||||
queryset = product_models.Attribute.objects.select_related('product').all()
|
||||
serializer_class = product_serializers.AttributeSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['name']
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=True,
|
||||
url_path='by_product',
|
||||
url_name='by_product',
|
||||
name='by_product'
|
||||
)
|
||||
def get_attributes_by_product(self, request, pk=None):
|
||||
""" get attributes by product with global ones """
|
||||
|
||||
attributes = self.queryset.filter(Q(is_global=True) | Q(product__id=pk))
|
||||
|
||||
serializer = self.serializer_class(attributes, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(
|
||||
methods=['put'],
|
||||
detail=True,
|
||||
|
||||
Reference in New Issue
Block a user