You could need an extra class for this but it should work: class Topping(models.Model): # ...
class Pizza(models.Model): # ... toppings = models.ManyToManyField(Topping) class PizzaToppings(model.Model): pizza = models.ForeignKey(Pizza, help_text='Toppings to go on Pizza: num in admin is how many will show up in Pizza', edit_inline=models.TABULAR, num_in_admin=3) topping = models.ManyToOne(Topping) #... some related material: http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships Hope that helps, Mn On May 31, 11:48 am, Gio <[EMAIL PROTECTED]> wrote: > Hi, > I searched about this subject and found only a few very old posts, so > maybe there is a better solution now. > > As you may guess the model I'd like to code is similar to the Pizza - > Toppings you know from the "Creating Models" documentation: > > class Topping(models.Model): > # ... > > class Pizza(models.Model): > # ... > toppings = models.ManyToManyField(Topping) > > And what if I need to say that I can have two or three times the same > topping on my pizza? Something like twice mozzarella cheese and 3 > times green olives topping? > > I though about an intermediary class and indeed this is the same > solution found in those old posts mentioned before: > > class Topping(models.Model): > # ... > > class ToppingAndQuantity(models.Model): > amount = models.IntegerField() > topping = models.ForeignKey(Topping) > > class Pizza(models.Model): > # ... > toppings = models.ManyToManyField(ToppingAndQuantity) > > I think it's ugly. > Can you suggest me a better solution? > It's that intermediary class really needed? > > Thank you, > Giovanni. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---