GithubHelp home page GithubHelp logo

Comments (8)

maerteijn avatar maerteijn commented on May 26, 2024 2

There is an example here of how to add images to the product list serializer. In the same way you could add a price as well: https://github.com/django-oscar/django-oscar-api/tree/master/demosite/mycustomapi

Let me know if this is a sufficient example for you.

from django-oscar-api.

ajithkjames avatar ajithkjames commented on May 26, 2024 1

Thanks for the reply @maerteijn .
I had seen this example from the docs. Added images to the products api that way. But not able to do that with price.
Here is how my serializers.py in the customapi app looks like

from rest_framework import serializers
from oscar.core import prices
from oscar.apps.partner.models import StockRecord
from oscarapi.utils import (
    OscarModelSerializer,
    overridable,
    OscarHyperlinkedModelSerializer
)
from oscarapi.serializers.product import (
    ProductImageSerializer, ProductLinkSerializer)
from oscarapi.serializers.checkout import PriceSerializer


class ProductPriceSerializer(OscarModelSerializer):
    class Meta:
        model = StockRecord
        fields = '__all__'


class CustomProductLinkSerializer(ProductLinkSerializer):
    images = ProductImageSerializer(many=True, required=False)
    price = ProductPriceSerializer(many=True, required=False)

    class Meta(ProductLinkSerializer.Meta):
        fields = ('url', 'id', 'title', 'images','price')

This doesn't work.
can you provide an example of doing it right way. Thanks

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024 1

Hi @ajithkjames

The price is dependent on the strategy, stockrecord, request, current user etc. That's why it's a little bit more complicated than just adding a field. See also the django oscar documentation about the Strategy class.

Basically, there are two options:
a) you overrride the view and add the price querying there
b) you override the serializer and add a SerializerMethodField because you need to add some code

For the second option I created an example here: https://github.com/django-oscar/django-oscar-api/blob/master/demosite/mycustomapi/serializers.py#L21

Let me know if this is sufficient for you.

from django-oscar-api.

ajithkjames avatar ajithkjames commented on May 26, 2024

thanks @maerteijn , It works!!

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

Ok cool. This example will be in the documentation for now on, I'll close this issue now.

from django-oscar-api.

Mohindharan avatar Mohindharan commented on May 26, 2024

@maerteijn this example is not valid anymore please reopen the issue.

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

@Mohindharan There is a working example in the documentation, see the part of customizing oscar api, so no need to reopen this issue.

from django-oscar-api.

Mohindharan avatar Mohindharan commented on May 26, 2024

@Mohindharan There is a working example in the documentation, see the part of customizing oscar api, so no need to reopen this issue.
thanks you for updating the docs

from django-oscar-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.