pip install djcommerce
- Add
djcommerce
toINSTALLED_APPS
INSTALLED_APPS = ( ... 'djcommerce', ... )
When you are referencing a model, we suggest you use the methods from djcommerce.utils
. For example, if you are setting a ForeignKey
to Address
, please set Address = get_address_model()
.
If you want to use the built in models, you do not need to do much configuration. However, if you want to inherit from the built in models, you need to create your own model, then in settings.py
define where your new model is via a string.
For example, let's say you have an address app with a custom address model in address/models.py
:
from djcommerce.models import Address
class MyCustomAddress(Address):
some_custom_field = models.CharField(max_length = 50)
In your settings.py
, you will then need to make a new variable ADDRESS_MODEL = 'address.models.MyCustomAddress'
so that it knows where to grab the address model for related models.
from djcommerce.models import Address
The Address
model has the following fields:
address_line_1
: This will hold the street number, name as well as suffixes and prefixes.address_line_2
: A nullable field for suite or unit numbercity
state
: AUSStateField
fromdjango-localflavor
zip
: AUSZipCodeField
fromdjango-localflavor
from djcommerce.models import Cart
The Cart
model has a products_in_cart
field, which is a ManyToManyField
, pointing to the ProductInCart
model.
You can inherit and create a new Cart
model, if the following conditions are met:
- The
products_in_cart
field must be aManyToManyField
- The object that the
ManyToManyField
is pointing to must have aget_subtotal
method, in order to be able to calculate the subtotal of the cart. Or, you can just avoid this by writing your ownget_subtotal
method on theCart
object.
from djcommerce.models import Category
Category
model allows for certain products to be listed under a certain category.
For example, if you are selling clothes, you may have a category of "shirts."
You would then create a Category
with a description
of "shirts."
from djcommerce.models import Configuration
The Configuration
model allows for the ability to create different versions of products, with the following fields:
name
: For example, size or color.options
: AManyToManyField
that points toConfigurationOption
. If the name of theConfiguration
is "size", then theoptions
could be 9M, 10M, 7F, 8F, etc.
The ConfigurationOption
model allows for options to the configuration with the following fields:
description
: The description of the option (for example, "9M", "10M", "7F" "8F").add_price
: The additional price to theprice
of the correspondingProduct
object.
from djcommerce.models import Order
Order
has a list of products, which is aManyToManyField
pointing to aProductInCart
.status
: The status of which stage of the order process the users order is in.get_subtotal
: Returns the subtotal of all of the products prices in the order combined.
from djcommerce.models import Product
Product
will be the main model that holds your ECommerce site's products, with the following fields:
name
categories
: AManyToManyField
that points to theCategory
modelstock
: AnIntegerField
that holds how many products you have in your inventoryprice
: The base price for the product.configurations
: These will hold the different possible configurations. For example, color, size, etc.
The ProductInCart
model has two fields:
product
: AForeignKey
that will be pointing to the Product.configuration_options
: AManyToManyField
that is connected to theConfigurationOption
object. This will allow for different configurations of a product in the same cart. For example, you may have a shoe product that has different sizes and colors. Theconfiguration_options
field will allow for a red shoe that is size 12 to be a differentProductInCart
instance than a blue shoe that is size 12.
from djcommerce.models import Profile
The Profile
model is used to extend the User model. Djcommerce uses a OneToOneField
to map a profile to a User, via the settings.AUTH_USER_MODEL
.
If you want to use this effectively, you can set up a signal when you create a new user that will automatically create a new corresponding Profile
model.