specialunderwear/django-easymode — pull request #10 by pvanderlinden (2012-05-15 12:33:02+00:00)
Title: ForeignKeyAwareAdmin: fix models in separate apps

It's hard to make a solid test for this, but I will try to explain.

When you put models with foreignkeys to the parent model in another app then the one of the parent model, ForeignKeyAwareAdmin doesn't always find children.

The reason it's hard to test:
All kind of design choices in django import all models before importing admin.py files fixing the problem:
- most management commands validates all models before doing anything other
- setting DEBUG to True also imports all models in all kinds of cases
- some middleware classes are also triggering the import of all models
- changing the order of your app's in INSTALLED_APPS will fix some of the problems too

So, running you website under WSGI, with DEBUG=False, and none of those middleware enters your code most of the time in the urls.py. On that location the admin.site.register() function is called, which initializes all admin classes. On the initialization ForeignKeyAwareAdmin will try to discover all the children, which fails because not all models are initialized.

Making it lazy, as in this pull request will fix this problem.