python - django models.py 文件中表名相互引用问题

有的项目可能会出现 A模块与B模块 中的某些表外键相互引用,但是正常引入模块的话会出现导入问题,解决方案如下:

 # 例如下面是目录结构(user, shop 在 apps 目录下)


apps
  user
    - views.py
    - models.py
        User

  shop
  - views.py
- models.py
Shop


# 这样导入就可以结局问题 # user 模块的 models.py 中 models.ForeignKey("shop.Shop") # shop 模块的 models.py 中 models.ForeignKey("user.User") # 只需要在 双引号 里面通过 "模块名.表名" 的方式就可以了

 

 

 

  

posted @ 2020-08-21 18:29  _Q  阅读(447)  评论(0编辑  收藏  举报