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.

customisation.rst 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ================
  2. Design decisions
  3. ================
  4. The central aim of oscar is to provide a solid core of an e-commerce project that can be
  5. extended and customised to suit the domain at hand. This is acheived in several ways:
  6. Core models are abstract
  7. ------------------------
  8. Online shops can vary wildly, selling everything from turnips to concert tickets. Trying
  9. to define a set of Django models capable for modelling all such scenarios is impossible -
  10. customisation is what matters.
  11. One way to model your domain is to have enormous models that have fields for
  12. every possible variation; however, this is unwieldy and ugly.
  13. Another is to use the Entity-Attribute-Value pattern to use add meta-data for each of
  14. your models. However this is again ugly and mixes meta-data and data in your database (it's
  15. an SQL anti-pattern).
  16. Oscar's approach to this problem is to have have minimal but abstract models
  17. where all the fields are meaningful within any e-commerce domain. Oscar then
  18. provides a mechanism for subclassing these models within your application so
  19. domain-specific fields can be added.
  20. Specifically, in each of oscar's apps, there is an ``abstract_models.py`` module which
  21. defines these abstract classes. There is also an accompanying ``models.py`` which provides an
  22. empty but concrete implementation of each abstract model.
  23. Classes are loaded dynamically
  24. ------------------------------
  25. To enable sub-apps to be overridden, oscar classes are loading generically
  26. using a special ``import_module`` function. This looks at the
  27. ``INSTALLED_APPS`` tuple to determine the appropriate app to load a class from.
  28. Within oscar itself, classes are imported using a special ``import_module`` function
  29. which determines which app to load the specified classes from. Sample usage is::
  30. import_module('product.models', ['Item', 'ItemClass'], locals())
  31. This will load the ``Item`` and ``ItemClass`` classes into the local namespace. It is
  32. a replacement for the usual::
  33. from oscar.product.models import Item, ItemClass
  34. The ``import_module`` looks through your ``INSTALLED_APPS`` for a matching module to
  35. the one specified and will load the classes from there. If the matching module is
  36. not from oscar's core, then it will also fall back to the equivalent module if the
  37. class cannot be found.
  38. This structure enables a project to create a local ``product.models`` module and
  39. subclass and extend the core models from ``oscar.app.product.models``. When Oscar
  40. tries to load the ``Item`` class, it will load the one from your local project.
  41. All views are class-based
  42. -------------------------
  43. This enables any view to be subclassed and extended within your project.
  44. Templates can be overridden
  45. ---------------------------
  46. This is a common technique relying on the fact that the template loader can be
  47. configured to look in your project first for templates, before it uses the defaults
  48. from oscar.