select quantity for each items selected in many to many field

classic Classic list List threaded Threaded
2 messages 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%2Bt3BPPr6m4jkeU0qPR00p5Aoun1h%2Bw7mi%2BYi5jqNf4WoQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: select quantity for each items selected in many to many field

Adam Johnson-2
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

On Fri, 19 Jul 2019 at 20:26, hunar techie <[hidden email]> wrote:
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%2Bt3BPPr6m4jkeU0qPR00p5Aoun1h%2Bw7mi%2BYi5jqNf4WoQ%40mail.gmail.com.


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM0kNcbS8oPC8f%3D9ztkG5zkGiPKMi%3DNN9H0ZB17uVqxrhA%40mail.gmail.com.