Adding productsΒΆ

To add products to the basket they need be registered in SALESMAN_PRODUCT_TYPES dictionary setting with values formated as 'app_name.Model': ''.


For this example we assume your custom app is named shop.

1. Create product model

First create a product model. Requirements are that it implements get_price(self, request) method and has properties name and code. Eg:

from django.db import models

class Product(models.Model):
    name = models.CharField(max_length=255)
    price = models.DecimalField(max_digits=18, decimal_places=2)

    def get_price(self, request):
        return self.price

    def code(self):
        return str(

2. Create product serializer

Then create a serializer for the product. Eg:

from rest_framework import serializers

from .models import Product

class ProductSerializer(serializers.ModelSerializer):
    class Meta:
        model = Product
        fields = ['name', 'code']

3. Register the product

Only thing left is to register it in

    'shop.Product': 'shop.serializers.ProductSerializer',

You can now add the product to the basket by sending a POST /basket/ request. In your request you should include product_type with value shop.Product and product_id with product instance id as value.