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

Update models.py to retrieve app_label from model meta if no app is specified #1448

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kigathi-chege
Copy link

Retrieve app_label from model meta if no app is specified

meta_fields["app_label"] = self.app if self.app else model._meta.app_label

replaces

if self.app:
     meta_fields["app_label"] = self.app

To ensure that the simple history model always has an app_label

Motivation and Context

I ran into this issue when developing an app for django that had an extra service that could integrate with any app, my service adds models into the app, and the models' histories are tracked using django simple history. Django threw the Model class doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. which prompted me to go down this road.

How Has This Been Tested?

This has only been tested in so far as it adds an app_label to models outside of an installed app. No official tests have been written.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have run the pre-commit run command to format and lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

Retrieve app_label from model meta if no app is specified
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

Successfully merging this pull request may close these issues.

1 participant