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.

fork_app.rst 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ==============
  2. Forking an app
  3. ==============
  4. This guide explains how to fork an app in Oscar.
  5. .. note::
  6. The following steps are now automated by the ``oscar_fork_app`` management
  7. command. They're explained in detail so you get an idea of what's going on.
  8. But there's no need to do this manually anymore! More information is
  9. available in :ref:`fork-oscar-app`.
  10. Create Python module with same label
  11. ====================================
  12. You need to create a Python module with the same "app label" as the Oscar app
  13. you want to extend. E.g., to create a local version of ``oscar.apps.order``,
  14. do the following::
  15. $ mkdir yourproject/order
  16. $ touch yourproject/order/__init__.py
  17. Reference Oscar's models
  18. ========================
  19. If the original Oscar app has a ``models.py``, you'll need to create a
  20. ``models.py`` file in your local app. It should import all models from
  21. the Oscar app being overridden::
  22. # yourproject/order/models.py
  23. # your custom models go here
  24. from oscar.apps.order.models import *
  25. If two models with the same name are declared within an app, Django will only
  26. use the first one. That means that if you wish to customise Oscar's models, you
  27. must declare your custom ones before importing Oscar's models for that app.
  28. You have to copy the ``migrations`` directory from ``oscar/apps/order`` and put
  29. it into your ``order`` app. Detailed instructions are available in
  30. :doc:`/howto/how_to_customise_models`.
  31. Get the Django admin working
  32. ============================
  33. When you replace one of Oscar's apps with a local one, Django admin integration
  34. is lost. If you'd like to use it, you need to create an ``admin.py`` and import
  35. the core app's ``admin.py`` (which will run the register code)::
  36. # yourproject/order/admin.py
  37. import oscar.apps.order.admin
  38. This isn't great but we haven't found a better way as of yet.
  39. Use supplied app config
  40. =======================
  41. Oscar ships with an app config for each app, which sets app labels and
  42. runs startup code. You need to make sure that happens.
  43. .. code-block: django
  44. # yourproject/order/config.py
  45. from oscar.apps.order import config
  46. class OrderConfig(config.OrderConfig):
  47. name = 'yourproject.order'
  48. # yourproject/order/__init__.py
  49. default_app_config = 'yourproject.order.config.OrderConfig'