Creating a product in django SHOP is really easy, but requires you to write python code.
The first step for you is to create a model to use as a product. We will create an example Book model together:
from shop.models import Product
from django.db import models
class Book(Product):
isbn = models.CharField(max_length=255)
class Meta: pass
Note
Your product subclass must define a Meta class. Usually, you will want to do so anyway, to define ordering and verbose names for example.
The following fields are already defined in the Product superclass:
The name/title of the product
The slug used to refer to this product in the URLs
Products flagged as not active will not show in the lists
The date at which the product was first created
A timestamp of when the product was last modified
The base price for one item
Like other objects in Django, you will need to create a template to display your model’s contents to the world.
By default, your Product subclass will use the shop/product_detail.html template as a fallback, but will use your own template if you follow Django’s naming conventions: appname/book_detail.html.
That’s all there is to it :)
Your product should behave like a normal Django model in all circumstances. You should register it in admin (and create an admin class for it) like a normal model.
Code wise, the following options are possible to retrieve your newly created model:
# This gets your model's instance the normal way, you get both your model's
# fields and the Product fields
o = MyProduct.objects.get(pk=...)
# This is also possible - You retrieve a MyProduct instance, using the
# Product manager
o = Product.objects.get(pk=...)
Note
This is possible thanks to the terrific django_polymorphic dependency
By design, django SHOP does not include an out of the box solution to handling product variations (colors, sizes...) in order to let implementors create their own unrestricted solutions.
If you want such a pre-made solution for simple cases, we suggest you take a look at the shop_simplevariations “add-on” application.