Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django signals file, cannot import model names

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.

like image 904
Hellnar Avatar asked Dec 07 '22 02:12

Hellnar


1 Answers

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.

like image 186
Daniel Roseman Avatar answered Dec 23 '22 23:12

Daniel Roseman