Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct the documentation of how to import extension snippets #1268

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading