Created
January 3, 2021 16:38
-
-
Save klement97/1a5212aec40d77a60c297def5024387c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pizza(models.Model): | |
name = models.CharField(max_length=100) | |
description = models.TextField(blank=True) | |
toppings = models.ManyToManyField(Topping, related_name='pizzas') | |
@property | |
def total_price(self) -> Decimal: | |
""" | |
Total price is sum of all topping prices. | |
""" | |
price = Decimal(0) | |
for topping in self.toppings.all(): | |
price += topping.price | |
return price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment