select quantity for each items selected in many to many field

234 views
Skip to first unread message

hunar techie

unread,
Jul 19, 2019, 8:40:48 PM7/19/19
to django-d...@googlegroups.com
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 

hunar techie

unread,
Jul 20, 2019, 7:31:53 AM7/20/19
to django-d...@googlegroups.com

Adam Johnson

unread,
Jul 21, 2019, 5:14:52 AM7/21/19
to django-d...@googlegroups.com
Hi!

I think you've found the wrong mailing list for this post. This mailing list is for the development of Django itself, not for support using Django. This means the discussions of bugs and features in Django itself, rather than in your code using it. People on this list are unlikely to answer your support query with their limited time and energy. Read more on the mailing lists at https://www.djangoproject.com/community/

I've had a quick read of your question, but I'm afraid I don't quite follow your data model enough to answer it right now.

For support, please use the django-users mailing list, or IRC #django on Freenode, or a site like Stack Overflow. There are people out there willing to help on those channels, but they might not respond if you don't ask your question well. Stack Overflow's question guide can help you frame it well: https://stackoverflow.com/help/how-to-ask .

Also if you haven't read it, please take a look at Django's Code of Conduct: https://www.djangoproject.com/conduct/ . These are our "ground rules" for working well as a community, and will help you get the most out of Django and our fantastic community.

Thanks for your understanding,

Adam

--
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 django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAKJtO%2Bt3BPPr6m4jkeU0qPR00p5Aoun1h%2Bw7mi%2BYi5jqNf4WoQ%40mail.gmail.com.


--
Adam
Reply all
Reply to author
Forward
0 new messages