Skip to content

Commit

Permalink
update FAQ entry on extension loading
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Sep 22, 2023
1 parent 7c3a9ad commit ae68f5c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,27 @@ call is proxied through the entrypoint.
Where should I put my extensions? / my extensions are not detected
------------------------------------------------------------------

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``.
The extensions register themselves automatically. Just be sure that the Python interpreter sees them at least once.
It is good practice to collect your extensions in ``YOUR_MAIN_APP_NAME/schema.py`` and to import that
file in your ``YOUR_MAIN_APP_NAME/apps.py``. Performing the import in the ``ready()`` method 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
While there are certainly other ways of loading your extensions, this is a battle-proven and robust way to do it.
Generally in Django/DRF, importing stuff in the wrong order often results in weird errors or circular
import issues, which this approach tries to carefully circumvent.


My ``@action`` is erroneously paginated or has filter parameters that I do not want
-----------------------------------------------------------------------------------
Expand Down

0 comments on commit ae68f5c

Please sign in to comment.