开发者

Django signals file, cannot import model names

开发者 https://www.devze.com 2023-01-04 09:31 出处:网络
I have such file order: project/ app/ models.py signals.py I am keeping signals inside signals.py as it should be. and at the top of the signals.py file, I include myapp models as I do queries in t

I have such file order:

project/
    app/
        models.py
        signals.py

I am keeping signals inside signals.py as it should be. and at the top of the signals.py file, I include myapp models as I do queries in these signals with

from myproject.myapp.models import Foo

开发者_高级运维However it doesnt seem to find it, as I run the server or validate from manage.py, it gives this error:

   from myproject.myapp.models import Foo
ImportError: cannot import name Foo

I am using Django 1.2.1.


Most likely you have a circular dependency. Does your models.py import the signals? If so, this can't work as both modules now depend on each other. You may need to import the models within a function in the signals file, rather than at the top level.

0

精彩评论

暂无评论...
验证码 换一张
取 消