Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

design_decisions.rst 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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
  9. tickets. Trying to define a set of Django models capable for modelling all such
  10. scenarios is impossible - 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 many 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 ``get_class`` function. This looks at the
  27. ``INSTALLED_APPS`` tuple to determine the appropriate app to load a class from.
  28. Sample usage::
  29. from oscar.core.loading import get_class
  30. Repository = get_class('shipping.repository', 'Repository')
  31. This is a replacement for the usual::
  32. from oscar.apps.shipping.repository import Repository
  33. It is effectively an extension of Django's ``django.db.models.get_model``
  34. function to work with arbitrary classes.
  35. The ``get_class`` function looks through your ``INSTALLED_APPS`` for a matching module to
  36. the one specified and will load the classes from there. If the matching module is
  37. not from oscar's core, then it will also fall back to the equivalent module if the
  38. class cannot be found.
  39. This structure enables a project to create a local ``shipping.repository`` module and
  40. subclass and extend the classes from ``oscar.app.shipping.repository``. When Oscar
  41. tries to load the ``Repository`` class, it will load the one from your local project.
  42. All views are class-based
  43. -------------------------
  44. This enables any view to be subclassed and extended within your project.
  45. Templates can be overridden
  46. ---------------------------
  47. This is a common technique relying on the fact that the template loader can be
  48. configured to look in your project first for templates, before it uses the defaults
  49. from oscar.