2

Possible Duplicate:
How can I have two foreign keys to the same model in Django?

New to Django, trying to wrap my head around how to set up this model. Basically I have a model called "Order" which lists the buyers information including one field which is takes a foreignkey(User). Not I want to add another field "seller" that relates to a different user who would be selling the order item, but django doesnt let me add another field relating to the same foreign key. What would be the proper way to set this model up? Thanks as always for your help in advance.

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)
Community
  • 1
  • 1
Jonathan
  • 219
  • 1
  • 11
  • 18
  • (See that question's accepted answer for a solution) – David Robinson Aug 16 '12 at 16:34
  • 2
    Actually, the answer right *after* the accepted answer has the solution, which is why it has more upvotes. Really, the accepted answer is nothing but conjecture with no actual path to solving the problem -- pretty useless. – Chris Pratt Aug 16 '12 at 17:13
  • 1
    The first answer does suggest using `related_name`, but I agree the next one is better. – David Robinson Aug 16 '12 at 17:27

0 Answers0