我试图建立一种关系,允许多个实体定期更新项目。更准确地说,我想定义模型中使用的术语。
Lead =>这将是项目。
公司=>允许对项目进行投标的承包商。在对项目进行投标/谈判时,他们必须定期更新领导的状态字段。
潜在客户更新=>表用于保持更新。
但是当我尝试运行服务器时,我收到此错误
"companies.leadupdate: Reverse query name for field 'lead' clashes with m2m field 'Lead.leadupdate'. Add a related_name argument to the definition for 'lead'"
我决定基于Django网站https://docs.djangoproject.com/en/1.4/topics/db/models/上的示例走这条路线,这与我想要实现的类似。我可能也完全关闭了:)
from django.db import models
class Company(models.Model):
comp_name = models.CharField(max_length=200)
comp_address = models.CharField(max_length=200)
comp_email = models.CharField(max_length=200)
comp_zip = models.IntegerField()
comp_phone = models.IntegerField()
comp_city = models.CharField(max_length=40)
def __unicode__(self):
return self.comp_name
class Leadsource(models.Model):
assetname = models.CharField(max_length=100)
def __unicode__(self):
return self.assetname
class Lead(models.Model):
numberofstations = models.IntegerField()
comment = models.CharField(max_length=500)
#company = models.ManyToManyField(Company)
leadsource = models.ForeignKey(Leadsource)
submissiondate = models.DateField('Submission Date')
cname = models.CharField('Business Name', max_length=100)
crep = models.CharField('Principle Contact', max_length=100)
cemail = models.CharField(max_length=100)
caddress = models.CharField(max_length=100)
cnumber = models.CharField(max_length=100)
leadupdate = models.ManyToManyField(Company,through='Leadupdate')
def __unicode__(self):
return u"%s %s %s" % (self.cname, self.crep, self.leadsource)
class Leadupdate(models.Model):
updatedate = models.DateField()
update = models.CharField(max_length=400)
updatefrom = models.ForeignKey(Company)
lead = models.ForeignKey(Lead)
def __unicode__(self):
return u" %s - %s " % (self.update, self.updatedate)
答案 0 :(得分:0)
与错误一样,尝试将related_name参数添加到Lead字段的定义中,例如:
lead = models.ForeignKey(Lead, related_name="lead_related")
这应该可以解决问题。