Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

design-decisions.rst 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ======================
  2. Oscar 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 achieved 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 modeling 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. The complexity of scenarios doesn't stop with Django models; core parts of
  26. Oscar need to be as customisable as possible. Hence almost all classes
  27. (including views) are
  28. :doc:`dynamically loaded </topics/class_loading_explained>`,
  29. which results in a maintainable approach to customising behaviour.
  30. URLs and permissions for apps are handled by Application instances
  31. ------------------------------------------------------------------
  32. The :class:`oscar.core.application.Application` class handles mapping URLs
  33. to views and permissions at an per-app level. This makes Oscar's apps more
  34. modular, and makes it easy to customise this mapping as they can be overridden
  35. just like any other class in Oscar.
  36. Templates can be overridden
  37. ---------------------------
  38. This is a common technique relying on the fact that the template loader can be
  39. configured to look in your project first for templates, before it uses the defaults
  40. from Oscar.