Monday, 12 August 2013

many to many vs new object with compound foreign keys in django

many to many vs new object with compound foreign keys in django

I have seen many to many relationships expressed explicitly in the model
like:
class Pizza(models.Model):
toppings = models.ManyToManyField(Topping, blank=True, null=True)
I have also seen people use an object with a compound object like this
class PizzaTopping(models.Model):
pizza = models.ForeignKey(Pizza)
topping = models.ForeignKey(Topping)
Is there a more preferable method of the two? If so, why?

No comments:

Post a Comment