python - 奇怪的 django 导入错误

标签 python django django-models django-errors

我试图做的是覆盖我的一个名为 Shastra

的模型的保存方法
class Shastra(models.Model):
    something = models.IntegerField()

    def save(self, *args, **kwargs):
        post_content(app='shastra', content=self)
        super(Shastra, self).save(*args, **kwargs)


# The function being called in the override function

def post_content(*args, **kwargs):  
     FbApiContent(content = kwargs['content']).save()


# The model being used by the override function

from shastra.models import Shastra

class FbApiContent(models.Model):

    content = models.ForeignKey(Shastra)

回溯

Traceback (most recent call last):
  File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\manage.py", line 14, in <module>
    execute_manager(settings)
  File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
    utility.execute()
  File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
    self.run(*args, **options)
  File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 78, in run
    self.inner_run(*args, **options)
  File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run
    self.validate(display_num_errors=True)
  File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors
    self._populate()
  File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 64, in _populate
    self.load_app(app_name)
  File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\shastra\models.py", line 10, in <module>
    from fb_api.api import *
  File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\api.py", line 7, in <module>
    from fb_api.models import FbApiUser
  File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\models.py", line 41, in <module>
    from shastra.models import Shastra
ImportError: cannot import name Shastra

我不知道发生了什么:|,任何见解我将不胜感激

最佳答案

循环导入。要么解决它,要么使用字符串作为 FK 参数 (models.ForeignKey('app.Shastra'))。

关于python - 奇怪的 django 导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979922/

相关文章:

python - 为什么相同的符号显示数组和矩阵的逐元素乘法,就像矩阵的乘法一样?

python - 如何使用 OpenCV 理解 Python 中的头部姿势估计角度?

python - keras.preprocessing.image.load_img 在调整大小时做了什么?

python - 如何加速 numpy.all 和 numpy.nonzero()?

django - 如何使用 celery 队列中的倒数计时器刷新任务

javascript - Django错误: Tuple or struct_time argument required

python - 在 django ORM、自定义查询集字段中使用计数和聚合(Sum)

使用 _set.all 的 Django 模板

Django - 网络商店模型组织

python - 防止 Django 模型中的 DateRangeField 重叠?