我正在尝试创建一个系统,以便某个用户对其他用户发表评论。因此,我创建了一个GenericRelation像这样的模型:
App1 \ models.py:
from django.contrib.auth.models import AbstractUser
from django.contrib.contenttypes.fields import GenericRelation
from app2.models import Social
class User(AbstractUser):
"""
Default User model used for authentification system
"""
relation = GenericRelation(Social) # recently added
App2 \ models.py:
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from app1.models import User
class Social(models.Model):
content_object = GenericForeignKey('content_type', 'object_id')
object_id = models.PositiveIntegerField()
content_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE)
author= models.ForeignKey(User, # Member who wrote the message
on_delete=models.CASCADE,
related_name='wrote')
message= models.TextField()
之前添加场relation在User。我没有任何问题,但我正在重做工作,GenericRelation我想简化我的鳕鱼。
然后当我运行服务器时出现问题。我处于递归导入循环中...
file .\app2\models.py
from app2.models import Social
file .\app1\models.py
from app1.models import User
是否有可能通过对“我的GenericRelation社交”和GenericRelation“我的社交媒体”保持关注来解决此问题User?因为之后我想GenericRelation(Social)在其他模型上添加另一个
烙印99
相关分类