Skip to content

Commit

Permalink
Merge pull request #1268 from n2ygk/patch-1
Browse files Browse the repository at this point in the history
Correct the documentation of how to import extension snippets
  • Loading branch information
tfranzel committed Jul 30, 2024
2 parents cc91637 + ec9dc1e commit f741899
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docs/blueprints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ Blueprint files can be found `here <https://github.com/tfranzel/drf-spectacular/

.. note:: Simply copy&paste the snippets into your codebase. The extensions register
themselves automatically. Just be sure that the python interpreter sees them at least once.
To that end, we suggest creating a ``PROJECT/schema.py`` file and importing it in your
``PROJECT/__init__.py`` (same directory as ``settings.py`` and ``urls.py``)
with ``import PROJECT.schema``. Now you are all set.
It is good practice to collect your extensions in ``YOUR_MAIN_APP_NAME/schema.py`` and importing that
file in your ``YOUR_MAIN_APP_NAME/apps.py``. Every proper Django app will already have an auto-generated
``apps.py`` file. Although not strictly necessary, doing the import in ``ready()`` is the most robust
approach. It will make sure your environment (e.g. settings) is properly set up prior to loading.

.. code-block:: python
# your_main_app_name/apps.py
class YourMainAppNameConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "your_main_app_name"
def ready(self):
import your_main_app_name.schema # noqa: E402
dj-stripe
---------
Expand Down

0 comments on commit f741899

Please sign in to comment.