|
|
@@ -8,9 +8,9 @@ extended and customised to suit the domain at hand. This is acheived in several
|
|
8
|
8
|
Core models are abstract
|
|
9
|
9
|
------------------------
|
|
10
|
10
|
|
|
11
|
|
-Online shops can vary wildly, selling everything from turnips to concert tickets. Trying
|
|
12
|
|
-to define a set of Django models capable for modelling all such scenarios is impossible -
|
|
13
|
|
-customisation is what matters.
|
|
|
11
|
+Online shops can vary wildly, selling everything from turnips to concert
|
|
|
12
|
+tickets. Trying to define a set of Django models capable for modelling all such
|
|
|
13
|
+scenarios is impossible - customisation is what matters.
|
|
14
|
14
|
|
|
15
|
15
|
One way to model your domain is to have enormous models that have fields for
|
|
16
|
16
|
every possible variation; however, this is unwieldy and ugly.
|
|
|
@@ -24,7 +24,7 @@ where all the fields are meaningful within any e-commerce domain. Oscar then
|
|
24
|
24
|
provides a mechanism for subclassing these models within your application so
|
|
25
|
25
|
domain-specific fields can be added.
|
|
26
|
26
|
|
|
27
|
|
-Specifically, in each of oscar's apps, there is an ``abstract_models.py`` module which
|
|
|
27
|
+Specifically, in many of oscar's apps, there is an ``abstract_models.py`` module which
|
|
28
|
28
|
defines these abstract classes. There is also an accompanying ``models.py`` which provides an
|
|
29
|
29
|
empty but concrete implementation of each abstract model.
|
|
30
|
30
|
|
|
|
@@ -32,27 +32,30 @@ Classes are loaded dynamically
|
|
32
|
32
|
------------------------------
|
|
33
|
33
|
|
|
34
|
34
|
To enable sub-apps to be overridden, oscar classes are loading generically
|
|
35
|
|
-using a special ``import_module`` function. This looks at the
|
|
|
35
|
+using a special ``get_class`` function. This looks at the
|
|
36
|
36
|
``INSTALLED_APPS`` tuple to determine the appropriate app to load a class from.
|
|
37
|
37
|
|
|
38
|
|
-Within oscar itself, classes are imported using a special ``import_module`` function
|
|
39
|
|
-which determines which app to load the specified classes from. Sample usage is::
|
|
|
38
|
+Sample usage::
|
|
40
|
39
|
|
|
41
|
|
- import_module('product.models', ['Item', 'ItemClass'], locals())
|
|
|
40
|
+ from oscar.core.loading import get_class
|
|
|
41
|
+
|
|
|
42
|
+ Repository = get_class('shipping.repository', 'Repository')
|
|
42
|
43
|
|
|
43
|
|
-This will load the ``Item`` and ``ItemClass`` classes into the local namespace. It is
|
|
44
|
|
-a replacement for the usual::
|
|
|
44
|
+This is a replacement for the usual::
|
|
|
45
|
+
|
|
|
46
|
+ from oscar.apps.shipping.repository import Repository
|
|
45
|
47
|
|
|
46
|
|
- from oscar.product.models import Item, ItemClass
|
|
|
48
|
+It is effectively an extension of Django's ``django.db.models.get_model``
|
|
|
49
|
+function to work with arbitrary classes.
|
|
47
|
50
|
|
|
48
|
|
-The ``import_module`` looks through your ``INSTALLED_APPS`` for a matching module to
|
|
|
51
|
+The ``get_class`` function looks through your ``INSTALLED_APPS`` for a matching module to
|
|
49
|
52
|
the one specified and will load the classes from there. If the matching module is
|
|
50
|
53
|
not from oscar's core, then it will also fall back to the equivalent module if the
|
|
51
|
54
|
class cannot be found.
|
|
52
|
55
|
|
|
53
|
|
-This structure enables a project to create a local ``product.models`` module and
|
|
54
|
|
-subclass and extend the core models from ``oscar.app.product.models``. When Oscar
|
|
55
|
|
-tries to load the ``Item`` class, it will load the one from your local project.
|
|
|
56
|
+This structure enables a project to create a local ``shipping.repository`` module and
|
|
|
57
|
+subclass and extend the classes from ``oscar.app.shipping.repository``. When Oscar
|
|
|
58
|
+tries to load the ``Repository`` class, it will load the one from your local project.
|
|
56
|
59
|
|
|
57
|
60
|
All views are class-based
|
|
58
|
61
|
-------------------------
|