-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
36 lines (29 loc) · 1.27 KB
/
models.py
File metadata and controls
36 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django.conf import settings
from django.db.models import (Model, AutoField, CharField, ForeignKey, IntegerField,
TextField, DecimalField, ManyToManyField,
CASCADE)
from inventory.models import QuantitativeUnit, Product
class Recipe(Model):
id = AutoField(primary_key=True)
instructions = TextField(blank=True)
ingredients = ManyToManyField(Product, through='Ingredient')
name = CharField(max_length=255)
user = ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=CASCADE,
null=True,
)
cook_time = IntegerField(blank=True, null=True)
prep_time = IntegerField(blank=True, null=True)
estimated_cost = DecimalField(max_digits=5, decimal_places=2, blank=True,
null=True)
url = CharField(max_length=255, blank=True)
def __str__(self):
return self.name
class Ingredient(Model):
product = ForeignKey(Product, on_delete=CASCADE)
recipe = ForeignKey(Recipe, on_delete=CASCADE, blank=True, null=True)
quantity = CharField(max_length=100, blank=True, null=True)
unit = ForeignKey(QuantitativeUnit, on_delete=CASCADE)
def __str__(self):
return f"{self.quantity} {self.unit} of {self.product.name}"