GithubHelp home page GithubHelp logo

Comments (12)

maerteijn avatar maerteijn commented on May 26, 2024 1

Take a look here, I created an example how to do it.

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024 1

Basically this is how django and restframework works, so there are no oscarapi specific things happening here. However, I will write some documentation about it to make it more clear. In the meanwhile take a look at the demosite.

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

You giving us really little details, so we can't guess what your problem is. However, I will try. If we take the example from the docs:

from django.utils.translation import get_language
from oscarapi.views import basic

class ProductList(basic.ProductList):
    def get_queryset(self):
        language = get_language()
        return super(ProductList, self).get_queryset().filter(
            locale=to_locale(language))

You can override the serializer class which is used by setting the serializer_class attribute:

from django.utils.translation import get_language
from oscarapi.views import basic
from my_serializers import MyCustomSerializer

class ProductList(basic.ProductList):
   serializer_class = MyCustomSerializer

    def get_queryset(self):
        language = get_language()
        return super(ProductList, self).get_queryset().filter(
            locale=to_locale(language))

from django-oscar-api.

ankur1708 avatar ankur1708 commented on May 26, 2024

Thanks @maerteijn but this doesn't work. After overriding, its still picking up the oscar api's serializer.

from django-oscar-api.

ankur1708 avatar ankur1708 commented on May 26, 2024

Here is the context @maerteijn :
I am trying to override serializer. I want image url, UPC etc as well with id and title of the product in GET /products API call. I am using oscar 1.1 and python 2.7

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

If that is the only thing you want please look at the settings for the serializers section. (Add OSCARAPI_PRODUCT_FIELDS to your django settings file and specify which fields you want in your serializer)

from django-oscar-api.

ankur1708 avatar ankur1708 commented on May 26, 2024

Thanks @maerteijn but few attributes like imageUrl (and size options) belongs to separate class: ProductImage. I am guessing overriding a serializer is the only option. Is there any other recommended way?

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

Well, that stays the same. If you take a look at the ProductList view:
https://github.com/django-oscar/django-oscar-api/blob/master/oscarapi/views/basic.py#L84

It defines a serializer_class attribute. So overriding the view and set another serializer class should work.

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

Maybe if you post your view, your custom serializer and urls.py I can help you debugging it

from django-oscar-api.

ankur1708 avatar ankur1708 commented on May 26, 2024

Thanks @maerteijn. This works. The only thing which was missing (and I am unable to get it) was '/api/products' entry in urls.py. The similar entry is already there in oscarapi's url.py. Does custom serializer getting picked because of this dup entry?
Also, I am going to add other relevant apis for multi vendor marketplace scenarios. Those should work smoothly now.

from django-oscar-api.

maerteijn avatar maerteijn commented on May 26, 2024

Yes, django will match the first url regex t will find in urls.py. So with defining this before oscarapi it matches your view (and your serializer as you defined in in your custom view)

from django-oscar-api.

SalahAdDin avatar SalahAdDin commented on May 26, 2024

@maerteijn Documentation please.

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.