select quantity for each items selected in many to many field

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

select quantity for each items selected in many to many field

namo
hi there i'm working on an restaurant ordering system , when someone order more than one product with different quantities for each product , be able to select its quantities 
it may order 3 Pizza with 2 sandwich , how to let the customer to define the quantities of each product , and then calculate with its prices  
 class Restaurant(models.Model):
    name = models.CharField(max_length=50)
    price = models.PositiveIntegerField(default=1)


    def __str__(self):
        return self.name

class Topping(models.Model):
    name = models.CharField(max_length=50)
    product_names = models.ManyToManyField(Restaurant, blank=True)
    quantity = models.PositiveIntegerField(default=1)


total price of orders , for one product for example : one pizza with one sandwich however they order more than one pizza and sandwich

    @property
    def total(self):  
        return self.product_names.aggregate(Sum('price'))['price__sum'] 

I expected to provide a quantity field for each selected items : pizza : 3 , sandwich:2 , then calculate them (3*pizza price , 2*sandwich price)

thanks for advice 

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAKJtO%2Bti%3Dh4jve4J6GSOhvWfWj-FB1-o0OAZv0EzzFEX1k-%2BiA%40mail.gmail.com.