When calling contrib.admin.site.register, other apps' models.py should not be loaded
|Reported by:||jcspray||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In a scenario where I have multiple apps, depending on one another, I may from time to time want to have a unidirectional sharing of models between apps. For example, I might have an app for articles, and then an app for comments which imports the models from articles in order to associate comments with them.
If each app's models.py file includes an import of django.contrib.admin and a series of admin.site.register calls, then the above setup is not possible, due to a circular dependency. This arises because invoking the admin from one model appears to indirectly load the models.py modules from other apps as well. I can work around this by only calling into contrib.admin from an app whose models.py file is not reused by any other apps, but this is much more ugly than having each models.py file register its own models with the admin.
So what I have to do at the moment is this:
articles models.py defines Article comments models.py imports articles.models.Article defines Comment registers Comment and Article with admin
But I should be able to do this:
articles models.py defines Article registers Article with admin comments models.py imports articles.models.Article defines Comment registers Comment with admin