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

Handling Missing Dynamic Models in Django's app_configs #328

Open
rajatb2814 opened this issue Aug 2, 2024 · 0 comments
Open

Handling Missing Dynamic Models in Django's app_configs #328

rajatb2814 opened this issue Aug 2, 2024 · 0 comments

Comments

@rajatb2814
Copy link
Contributor

Currently, models present in packages or modules are not initialized in app_configs of apps within the django.apps module.
This leads to issue where the models are not returned with apps.get_models(). This have implications on some default functions given by ContentType model like model_class()

Proposed Solution:

To address this, I propose an enhancement to dynamically update app_configs with models discovered at runtime. Specifically, we can introduce a mechanism to update app_configs with dynamic models when running the server or executing commands.

Implementation Details:

Retrieve Dynamic Models: Obtain a list of all dynamic models that need to be registered.
Update app_configs: Modify the app_configs dictionary to include these dynamic models. This can be achieved by updating the models attribute of the relevant AppConfig instances.

Example Code Snippet:

from django.apps import apps
app_config = apps.app_configs.get('dynamic_models')
if app_config:
app_config.models.update({
'<model_name>': <model_class>
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant