Свойство данных сериализатора DRF не переопределено
У меня есть следующий сериализатор, где мне нужно переопределить свойство data, но по какой-то причине оно не переопределяется вообще.
class ShopItemListSerializer(AvailabilitySerializerFieldMixin, serializers.ModelSerializer):
is_aggregation_product = serializers.BooleanField()
price = MoneyField(allow_null=True)
discount_price = serializers.SerializerMethodField()
is_favorite = serializers.SerializerMethodField()
categories = ShopItemCategorySerializer(many=True)
price_effect = ProductPriceEffectSerializer(source="aggregation_product.price_effect")
special_information = serializers.CharField()
@property
def data(self):
logging.error("I should be overridden")
ret = super().data
return_dict = ReturnDict(ret, serializer=self)
if self.context.get("include_unavailable", False) is True:
""" remove products that are not available """
for product in return_dict.copy():
if product["availability"] and product["availability"]["is_available"] is True:
return_dict.remove(product)
return return_dict
Я использую следующие наборы представлений:
class ProductViewSet(StorePickupTimeSerializerContextMixin, ReadOnlyModelViewSet):
queryset = ShopItem.app_visibles.prefetch_related("pictures").distinct()
permission_classes = [IsCustomer]
filter_backends = (filters.DjangoFilterBackend, SearchFilter, OrderingFilterWithNoneSupport)
filterset_class = ShopItemFilter
search_fields = ["name", "number", "categories__name"]
def get_serializer_class(self):
if self.action == "list":
return ShopItemListSerializer
return ShopItemProductDetailSerializer
Буду признателен за любые соображения, объясняющие причину такого поведения.