我有以下2个模型,我想将它们与ManyToMany关系链接:
WWW / hruser / models.py
from django.db import models
class HRuser(models.Model):
"""Custom user class."""
email = models.EmailField(max_length=60, unique=True, db_index=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
video = models.ManyToManyField('www.pandastream.models.Video', related_name='users')
WWW / pandastream / models.py
from django.db import models
from www.hruser.models import HRuser
class Video(models.Model):
"""Video object, really basic for now."""
video_id = models.CharField(max_length=32, unique=True, db_index=True)
user = models.ForeignKey(HRuser, related_name='videos')
正如您所看到的,它们位于不同的应用中,而Video也有一个到HRuser的ForeignKey。
为避免www/hruser/models.py
中的循环导入,我尝试使用文档中定义的here之间的惰性关系,但它在syncdb上引发错误:
Error: One or more models did not validate:
hruser.hruser: 'video' has an m2m relation with model www.pandastream.models.Video, which has either not been installed or is abstract.
到目前为止,我已经尝试过:
HRuser.video
字段更改为简单的ForeignKey字段django.core.management.validation
所有这些都没有改变我的问题,所以要么我不正确理解文档或文档是错误的,但无论哪种方式,任何帮助将不胜感激。
答案 0 :(得分:0)
如文档链接中所述,将目标作为字符串引用的方式为"appname.Model"
。所以它应该是"pandastream.Video"
。