Adding products

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


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

1. Create product models

First, create a product model. It must implement the salesman.core.typing.Product protocol. Required methods and attributes are: id, name, code, get_price(self, request).

from django.db import models

class Product(models.Model):
    Simple single type product.

    name = models.CharField(max_length=255)
    price = models.DecimalField(max_digits=18, decimal_places=2, default=0)

    def __str__(self):

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

    def code(self):
        return str(

2. Create product serializers

Then create a serializer for the product. Eg:

from rest_framework import serializers

from . import models

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

3. Register the product types

The 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 set as shop.Product and product_id with product instance id as the value.