On Tue, 23 Dec 2014 02:23:16 -0800 (PST)
su...@janakitech.com wrote:

> I have following model.
> 
> class CampaignTemp(models.Model):
>     campaign_modules = Module.objects.filter(active=True)
>     choices = ....
>     ...
>     ... # other fields 
> 
> I get following error when I try `python manage.py`.
> ...
> File "/home/auser/aproject/src/apps/anapp/models.py", line 35, in 
> CampaignTemp
>     campaign_modules = Module.objects.filter(active=True)
> ...
> django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
> ...
> 
> The code was written for Django1.6 and is being ported to 1.7. Any help 
> would be appreciated.
> 

You're doing it wrong. You should never try to access data from database when
constructing models (or load modules) since there is no guarantee that "Module" 
model
is completely initialized and working properly.

Since you don't provide more details I assume that you try to have dynamic from 
Module to
fill choices. There are two fundamental problems first is what happens above 
and second
is that campaign_modules is only evaluated _once_ in lifetime of a CampaignTemp 
model. So
if you change active status of modules they're not reflected to that list.

You need to provide more context of your model so we can help with proper 
solution.

-- 

Jani Tiainen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141223152847.16290ac5%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to