> > 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.
>
> So, settings isn't actually run properly (and thus the apps in
> INSTALLED_APPS aren't all imported) when doing
>
> $ DJANGO_SETTINGS_MODULE=settings python script.py
>
> ?
>
> So how is one supposed to do such things without going trough manage.py then?
>
> HM
*Do* go through manage.py. Write your script as a custom manage.py