但是我在一些序列化器中使用ProductSerializer。我无法在视图中覆盖查询集。
class RentalProductSerializer(serializers.ModelSerializer):
photos = RentalProductPhotoSerializer(read_only=True, many=True)
class Meta:
model = Product
list_serializer_class = ProductListSerializer
fields = ['categories', 'stock_code', 'description', 'brand', 'model_name', 'photos', 'url']
class RentalOfferLineSerializer(serializers.ModelSerializer):
product_detail = RentalProductSerializer(read_only=True, many=False, source='product')
class Meta:
model = RentalOfferLine
fields = (
'id',
'product',
'product_detail',
'currency',
'rent_price',
'quantity',
)