可能重复:
How can I have two foreign keys to the same model in Django?
Django的新手,试图围绕如何设置这个模型。基本上我有一个名为“Order”的模型,它列出了买家信息,包括一个带外键(用户)的字段。不是我想添加另一个与销售订单商品的不同用户相关的字段“卖家”,但是django不允许我添加与同一外键相关的另一个字段。设置此模型的正确方法是什么?一如既往地感谢您的帮助。
class Order(models.Model):
date = models.DateTimeField(auto_now_add=True)
buyer = models.ForeignKey(User, null=True)
transaction_id = models.CharField(max_length=20)
email = models.EmailField(max_length=50)
phone = models.CharField(max_length=20)
shipping_name = models.CharField(max_length=50)
shipping_address_1 = models.CharField(max_length=50)
shipping_address_2 = models.CharField(max_length=50)
shipping_city = models.CharField(max_length=50)
shipping_state = models.CharField(max_length=2)
shipping_zip = models.CharField(max_length=10)
billing_name = models.CharField(max_length=50)
billing_address_1 = models.CharField(max_length=50)
billing_address_2 = models.CharField(max_length=50, blank=True)
billing_city = models.CharField(max_length=50)
billing_state = models.CharField(max_length=2)
billing_country = models.CharField(max_length=50)
billing_zip = models.CharField(max_length=10)
def __unicode__(self):
return 'Order #' + str(self.id)