我有一个Customer类通过外键链接到其他几个类。我希望表单以这样的方式工作:如果提交的客户记录已经存在,那么此记录将用作依赖类的外键。
我已将Customer类声明为:
class Customer(CustomerBaseInfo):
date_time_added = models.DateTimeField(default=datetime.today)
source = models.ForeignKey(Source, blank=False)
email_address = models.CharField(max_length=75)
phone_number = models.CharField(max_length=20)
preffered_contact_method = models.ForeignKey(PreferredContact)
best_time_to_contact = models.ForeignKey(BestTime)
def __unicode__(self):
return self.first_name
链接到Customer类的其中一个类看起来像这样:
class Message(models.Model):
date_time_added = models.DateTimeField(default=datetime.today)
message_type = models.ForeignKey(MessageType)
customer = models.ForeignKey(Customer)
representative = models.ForeignKey(Representative)
vehicle = models.CharField(max_length=80)
message = models.TextField(null=True)
def __unicode__(self):
return self.date_time_added