奇怪的Django导入错误

2024-09-29 17:14:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我所要做的是重写我的一个模型的save方法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)

回溯

^{pr2}$

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


Tags: theselfmodelmodelssavedefargsfunction
2条回答

看起来你有一个循环导入。在

shastra\models.py正在执行from fb_api.api import *

fb_api\api.py正在执行from fb_api.models import FbApiUser

fb_api\models.py正在执行from shastra.models import Shastra

即使您只是从一个模块导入一个类,整个模块也会被执行来填充它的命名空间。在

循环导入。解析它,或者使用string作为FK参数(models.ForeignKey('app.Shastra'))。在

相关问题 更多 >

    热门问题