On 23-8-2012 20:15, Kurtis Mullins wrote:

> class Factory(models.Model):
>     # Assuming suppliers and customers are just two sides of the same
> relationship
>     suppliers = models.ManyToManyField("self", related_name="customers")
> 
> Then simply query accordingly:
> 
> factory_a = Factory.objects.create()
> factory_b = Factory.objects.create()
> factory_c = Factory.objects.create()
> factory_b.customers.add(factory_a)
> factory_c.suppliers.add(factory_a)

Just a "heads up". This works as long as you only have factories. If you
add other entities like "exporters" and "wholesalers" you're going to
need generic relations:
<https://docs.djangoproject.com/en/1.4/ref/contrib/contenttypes/#generic-relations>

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to