Data model¶
Data in Shoop is stored into database using regular Django models and it is accessed with Django’s normal query
API. See shoop.core.models for list of
models in Shoop Core.
Extending models¶
Non-polymorphic models¶
Basic models (like Product,
Category or
Order) cannot be replaced. To extend them,
create a new model for your extensions and link that to the original
model with a OneToOneField.
For example:
from django.core import models
from shoop.core import models as shoop_models
class MyProduct(models.Model):
product = models.OneToOneField(shoop_models.Product)
# fields of the extension...
my_field = models.CharField(max_length=10)
...
Todo
Check Multi-table inheritance for extending models
Note
Even though basic models cannot be replaced, it is possible to
replace the User model. See
Specifying a custom User model.
Polymorphic models¶
Polymorphic models (like Contact) can be
extended by inheritance. The polymorphic base class has a model
manager that makes sure that the returned
objects are correct type. For example, when getting all
Contacts with a query like
Contact.objects.all(), the returned
QuerySet may have instances of
PersonContact,
CompanyContact and your custom class.
See django-polymorphic’s documentation for details.