I have 3 django models like this
To keep record of orders
class Orders(models.Model):
restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE, blank=True, null=True)
total_amount = models.DecimalField(max_digits=10, decimal_places=2)
which articles are in order like pizza etc
class OrderArticle(models.Model):
order = models.ForeignKey(Orders, on_delete=models.CASCADE)
article = models.ForeignKey(Articles, on_delete=models.CASCADE)
Article options of articles in order (like topping on pizza , now topping can be 4 or more types)
class OrderArticleOptions(models.Model):
article_option = models.ForeignKey(ArticlesOptions, on_delete=models.CASCADE)
order_article = models.ForeignKey(OrderArticle, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=10, decimal_places=2)
To keep track of this multipul type of Article options I made this table . So example will be . Customer purchased a pizza with 2 toppings , 1st topping fajita quantiity is 1 and 2nd topping oliva quantity is 3 .
to get this use case using Django Rest framework what should I do ?
Issue
I want data like this
data {
orders[
article1
{
articleoptio1
{}
articleoption2
{}
}
]
}
Now issue is when I add 2 type of toppings to a single article in order, it creates 2 diff orders with 2 articles with each article option. While I want 1 article with 2 article options .