specialunderwear / django-easymode

Quickly build backends for flash/flex websites with Django.
GNU General Public License v3.0
35 stars 20 forks source link

ForeignKeyAwareAdmin: fix models in separate apps #10

Closed pvanderlinden closed 12 years ago

pvanderlinden commented 12 years ago

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:

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.

pvanderlinden commented 12 years ago

I know, this is a fix for some old projects with problems.