Django.core.exceptions.AppRegistryNotReady: models not yet loaded

In Django 1.7, this code caused errors in django.setup() :

 class MyModel(models.Model): special_foo=Foo.objects.filter(name__contains='special') 

In my case, I got this:

 django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. 

But I saw recursion errors in django.setup() trying again to start django.setup() .

0
source share
1 answer

I solved this with class level properties.

 class MyModel(models.Model): @classproperty def special_foo(cls): return Foo.objects.filter(name__contains='special') 

Unfortunately, python does not support @classproperty out of the box.

I used the implementation here fooobar.com/questions/92522 / ...

0
source

Source: https://habr.com/ru/post/1206202/


All Articles