Change History (8)

It is not very good practice to import admin business inside a models.py, both conceptually (if we care about MVC) and technically (potential circular imports). Is that something that used to work, and if so, in which version of Django?

Worked in 1.2.1. Was extending it to make our admin interface a bit friendlier, but not wholly necessary now that we import our data from an LDAP directory. Figured if something used to work and doesn't now that's probably a bug.

The admin import system is quite convoluted and, like I've pointed out above, importing admin stuff into a models.py seems like not so good practice in the first place anyway. On that basis I'm wontfixing this. Please reopen if you have a strong use-case that cannot be filled using a better approach.

The underlying problem here is likely the same as #11247/#11448, it has been around for a long time. Possibly something has changed in the contrib.auth code to trigger it now where it wasn't triggered in the past. While it is true that intermixing model and admin definitions is generally bad practice, getting the underlying bug fixed would be a good idea. It's not particularly nice that a harmless-looking sequence of imports (even if they are not best practice) would cause this kind of side-effect.

Thanks for this info. I agree that it'd be nice to solve this bug, which #11448 appears to be addressing at the root. In the particular instance here, my point was that in order to work the admin has to do some pretty convoluted imports, leading to some inevitable limitations. For example, the recommended place to do autodiscover() is in the main urls.py because it is assumed that by the time that module gets loaded all models have already been imported. So the admin already does prevent some things that you may like to do, and if those things aren't best practice, then it's something that we can live with. But yeah, we should fix this bug if we can (via #11448).

Can you please try replacing the Django 1.3 with a fresh checkout of the bugfixes-ony 1.3.X SVN branch and repating your test? I'm particularly interested in knowing if this could have been solved by r16541. Thanks.