使用用户字段设置django模型两次

时间:2012-08-16 16:25:40

标签: python django

  

可能重复:
  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)

0 个答案:

没有答案