summaryrefslogtreecommitdiff
path: root/recipe/models.py
blob: fc611a3599dd935fc60c820b4fbbb08a1e1c35db (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from django.db import models
from django.db.models import fields


class Unit(models.Model):

    class Meta:
        ordering = ('name',)

    name = fields.CharField(max_length=100)
    abbreviation = fields.CharField(max_length=10, blank=True, null=True)

    def __unicode__(self):
        return "{0} ({1})".format(self.name, self.abbreviation)


class Recipe(models.Model):

    class Meta:
        ordering = ('title',)

    title = fields.CharField(max_length=100)
    slug = fields.SlugField(max_length=150)
    description = fields.TextField(blank=True, null=True)
    servings = fields.IntegerField(blank=True, null=True)
    instructions = fields.TextField()
    oven_temp = fields.IntegerField(blank=True, null=True)
    cook_time = fields.IntegerField(blank=True, null=True, help_text="In minutes")
    prep_time = fields.IntegerField(blank=True, null=True, help_text="In minutes")

    def __unicode__(self):
        return self.title


class Ingredient(models.Model):

    class Meta:
        ordering = ('name',)

    name = fields.CharField(max_length=100, unique=True)

    def __unicode__(self):
        return self.name


class RecipeIngredient(models.Model):

    ingredient = models.ForeignKey(Ingredient)
    units = models.ForeignKey(Unit)
    quantity = fields.FloatField()
    recipe = models.ForeignKey(Recipe)

    def __unicode__(self):
        return "{0} in {1}".format(self.ingredient.name, self.recipe.title)