select quantity for each items selected in many to many field

15 views
Skip to first unread message

namo

unread,
Jul 20, 2019, 8:13:54 AM7/20/19
to Django users
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 
Reply all
Reply to author
Forward
0 new messages