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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. .. note::
  11. Because of the way dynamic class loading works, when forking dashboard apps,
  12. the ``oscar.apps.dashboard`` app also needs to be forked; and the forked
  13. dashboard app's code must live inside the forked ``oscar.apps.dashboard``
  14. app's directory.
  15. Similarly, when forking ``oscar.apps.catalogue.reviews``,
  16. ``oscar.apps.catalogue`` needs to be forked as well; and the forked
  17. ``oscar.apps.catalogue.reviews`` app's code must live inside the forked
  18. ``oscar.apps.catalogue`` app's directory.
  19. Create Python module with same label
  20. ====================================
  21. You need to create a Python module with the same "app label" as the Oscar app
  22. you want to extend. E.g., to create a local version of ``oscar.apps.order``,
  23. do the following::
  24. $ mkdir yourproject/order
  25. $ touch yourproject/order/__init__.py
  26. Reference Oscar's models
  27. ========================
  28. If the original Oscar app has a ``models.py``, you'll need to create a
  29. ``models.py`` file in your local app. It should import all models from
  30. the Oscar app being overridden::
  31. # yourproject/order/models.py
  32. # your custom models go here
  33. from oscar.apps.order.models import *
  34. If two models with the same name are declared within an app, Django will only
  35. use the first one. That means that if you wish to customise Oscar's models, you
  36. must declare your custom ones before importing Oscar's models for that app.
  37. You have to copy the ``migrations`` directory from ``oscar/apps/order`` and put
  38. it into your ``order`` app. Detailed instructions are available in
  39. :doc:`/howto/how_to_customise_models`.
  40. Get the Django admin working
  41. ============================
  42. When you replace one of Oscar's apps with a local one, Django admin integration
  43. is lost. If you'd like to use it, you need to create an ``admin.py`` and import
  44. the core app's ``admin.py`` (which will run the register code)::
  45. # yourproject/order/admin.py
  46. import oscar.apps.order.admin
  47. This isn't great but we haven't found a better way as of yet.
  48. Use supplied app config
  49. =======================
  50. Oscar ships with an app config for each app, which sets app labels and
  51. runs startup code. You need to make sure that happens.
  52. .. code-block: django
  53. # yourproject/order/apps.py
  54. from oscar.apps.order import apps
  55. class OrderConfig(apps.OrderConfig):
  56. name = 'yourproject.order'
  57. # yourproject/order/__init__.py
  58. default_app_config = 'yourproject.order.apps.OrderConfig'