Extending django-oscarapi API ROOT to custom API class

这一生的挚爱 提交于 2019-12-13 15:45:01

问题


I have a django oscar application and I use django-oscarapi for my custom APIs. Some things are missing from the oscarapi like category and promotions but I have been able to use django-restframework to create the category API but the challenge I am facing now is how to add it to the API-ROOT. This is my code for rendering categories

customapi serializer class

class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = Category
        fields = ('id', 'numchild', 'name', 'description', 'image', 'slug')

Views

class CategoryList(generics.ListAPIView):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer


class CategoryDetail(generics.RetrieveAPIView):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer

customapi/urls.py

url(r'^caty/$', CategoryList.as_view(), name='category-list'),
url(r'^caty/(?P<category_slug>[\w-]+(/[\w-]+)*)_(?P<pk>\d+)/$',
        CategoryDetail.as_view(), name='category'),

Thanks in advance

来源:https://stackoverflow.com/questions/50666739/extending-django-oscarapi-api-root-to-custom-api-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!