On Mon, Nov 23, 2009 at 1:59 AM, Hanne Moa <hanne....@gmail.com> wrote:
> I have models M, N, which both have a foreignkey to User. When in the
> shell/runserver, User has attributes for both M and N, but in a
> batchfile ($ DJANGO_SETTINGS_MODULE=settings python batch.py) only M
> is reachable from User while trying to get N leads to
>
> AttributeError: 'User' object has no attribute 'N_set'
>
> Wherever and how do I start debugging something like this?

If model X has a foreign key pointing to model Y, model Y won't get
the X_set attribute until model X is actually imported. This means
that if X isn't imported, attributes will appear to be missing from Y.

When you run under runserver, the INSTALLED_APPS setting is
effectively an implied import of all the models listed. However,
provided you have the right tables in your database, you can sometimes
successfully use an app (i.e., import it and use the models) without
the app being listed in INSTALLED_APPS.

As a result, the behaviour you are seeing could be caused if:
 * You aren't importing the N model in your standalone script (either
due to an import error of some kind, or you simply aren't doing the
import), or
 * The code that runserver is executing imports model N, but the app
that defines N isn't listed in INSTALLED APPS

So - this will require some forensic work on your part, but I suspect
you need to look very closely at imports and import failures.

Yours,
Russ Magee %-)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.


Reply via email to