You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

how_to_customise_models.rst 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. =======================
  2. How to customise models
  3. =======================
  4. You must first create a local version of the app that you wish to customise. This
  5. involves creating a local app with the same name and importing the equivalent models
  6. from oscar into it.
  7. Example
  8. -------
  9. Suppose you want to add a video_url field to the core product model. This means that
  10. you want your application to use a subclass of ``oscar.apps.catalogue.models.Product`` which
  11. has an additional field.
  12. The first step is to create a local version of the "catalogue" app. At a minimum, this
  13. involves creating ``catalogue/models.py`` within your project and changing ``INSTALLED_APPS``
  14. to point to your local version rather than oscar's.
  15. Next, you can modify the ``Product`` model through subclassing::
  16. # yourproject/catalogue/models.py
  17. from django.db import models
  18. from oscar.apps.catalogue.abstract_models import AbstractProduct
  19. class Product(AbstractProduct):
  20. video_url = models.URLField()
  21. Now, running ``./manage.py syncdb`` will create the product model with your additional field