forked from django-oscar/django-oscar
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4996038
commit 08ed55e
Showing
7 changed files
with
150 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
============================ | ||
How to override a core class | ||
============================ | ||
|
||
Example | ||
------- | ||
|
||
Suppose you want to alter the way order number's are generated. By default, | ||
the class ``oscar.apps.order.utils.OrderNumberGenerator`` is used. To change | ||
the behaviour, you need to ensure that you have a local version of the | ||
``order`` app (ie ``INSTALLED_APPS`` should contain ``yourproject.order``, not | ||
``oscar.apps.order``). Then create a class within your ``order`` app which | ||
matches the module path from oscar: ``order.utils.OrderNumberGenerator``. This | ||
could subclass the class from oscar or not. An example implementation is:: | ||
|
||
# yourproject/order/utils.py | ||
from oscar.apps.order.utils import OrderNumberGenerator as CoreOrderNumberGenerator | ||
|
||
|
||
class OrderNumberGenerator(CoreOrderNumberGenerator): | ||
def order_number(self, basket=None): | ||
num = super(OrderNumberGenerator, self).order_number(basket) | ||
return "SHOP-%s" % num | ||
|
||
the same module path as the one from oscar, that is, | ||
|
||
Discussion | ||
---------- | ||
|
||
This principle of overriding classes from modules is an important feature of oscar | ||
and makes it easy to customise virtually any functionality from the core. For this | ||
to work, you must ensure that: | ||
|
||
1. You have a local version of the app, rather than using oscar's directly | ||
2. Your local class has the same module path relative to the app as the oscar | ||
class being overridden | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters