【发布时间】:2018-10-05 09:25:19
【问题描述】:
我有两个类,它们之间有两个多对多关系。由于相邻的表还必须具有其他属性,因此我明确定义了它们。但我收到一条错误消息,提示我需要更改相关名称。不知道在哪里做这个。非常感谢任何帮助。
这是我的 models.py 代码:
class Client(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.CharField(max_length=255)
password = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
objects = UserManager()
def __repr__(self):
return "<User object: {} {} {} {}>".format(self.first_name,
self.last_name, self.email, self.password)
class Therapist(models.Model):
name = models.CharField(max_length=255)
reviews = models.ManyToManyField(Client, through="Review")
appts = models.ManyToManyField(Client, through="Appointment")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
objects = UserManager()
def __repr__(self):
return "<Book object: {}>".format(self.title)
class Review(models.Model):
reviewer = models.ForeignKey(Client, on_delete=models.CASCADE)
therapist_reviewed = models.ForeignKey(Therapist,
on_delete=models.CASCADE)
rating = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
content = models.TextField()
def __repr__(self):
return "<Review object: {} {}>".format(self.book_reviewed,
self.reviewer)
class Appointment(models.Model):
booked_therapist = models.ForeignKey(Therapist,
on_delete=models.CASCADE)
booked_client = models.ForeignKey(Client, on_delete=models.CASCADE)
date = models.DateTimeField()
massage = models.CharField(max_length=255)
【问题讨论】:
-
请分享回溯
-
错误:application.Therapist.appts:(fields.E304)“Therapist.appts”的反向访问器与“Therapist.reviews”的反向访问器冲突。提示:在“Therapist.appts”或“Therapist.reviews”的定义中添加或更改related_name 参数。 application.Therapist.reviews:(fields.E304)“Therapist.reviews”的反向访问器与“Therapist.appts”的反向访问器发生冲突。提示:在“Therapist.reviews”或“Therapist.appts”的定义中添加或更改related_name 参数。
标签: django many-to-many models