Using Overriden Serializer in custom Object Serializer
MLI-DS opened this issue · comments
Hi,
This is more of a question on how to use the package then a potential issue with the package
I have overriden my product serializer like so:
class ProductSerializer(product.ProductSerializer):
price = serializers.SerializerMethodField()
stockrecords = product.ProductStockRecordSerializer(many=True, required=False)
def get_price(self, instance):
request = self.context.get("request")
strategy = Selector().strategy(request=request, user=request.user)
ser = checkout.PriceSerializer(
strategy.fetch_for_product(instance).price,
context={'request': request})
return ser.data
And defined
OSCARAPI_OVERRIDE_MODULES = ["apps.OscarCustoms.oscarapi"]
and the product end point has been properly overwritten and outputs the desired json ( see https://stage.ski-family.fr/api/products/210/ )
Now I would like to add this piece of json to a custom object serializer by passing my product serializer to the field corresponding to a product.
I have tried the following:
from apps.OscarCustoms.oscarapi.serializers.product import ProductSerializer
class LessonSerializer(serializers.ModelSerializer):
variation = ProductSerializer()
meeting_point = MeetingPointSerializer()
level = LevelSerializer()
instructor = InstructorSerializer()
class Meta:
model = Lesson
fields = '__all__'
How ever this ends up giving me an AppRegistryNotReadyError when running tests and a maximum depth recursion error when loading my drf-yasg doc.
Any pointers on why this could be happening and the right way to load in the overriden serializer ?
Does it help when you try it like this:
from oscarapi.utils.loading import get_api_class
ProductSerializer = get_api_class("serializers.product", "ProductSerializer")
@MLI-DS Did you try the above and did it help?
Closing issue due to inactivity