diff options
Diffstat (limited to 'greenbox/recipe/models.py')
-rwxr-xr-x | greenbox/recipe/models.py | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/greenbox/recipe/models.py b/greenbox/recipe/models.py index 71a8362..1c23eda 100755 --- a/greenbox/recipe/models.py +++ b/greenbox/recipe/models.py | |||
@@ -1,3 +1,71 @@ | |||
1 | from django.contrib import admin | ||
2 | from django.contrib.admin import ModelAdmin, TabularInline | ||
1 | from django.db import models | 3 | from django.db import models |
4 | from django.db.models import CharField, IntegerField, TextField, FloatField | ||
5 | from django.db.models import ForeignKey | ||
2 | 6 | ||
3 | # Create your models here. | 7 | |
8 | class Unit(models.Model): | ||
9 | |||
10 | name = CharField(max_length=100) | ||
11 | abbreviation = CharField(max_length=10, blank=True, null=True) | ||
12 | |||
13 | def __unicode__(self): | ||
14 | return "{0} ({1})".format(self.name, self.abbreviation) | ||
15 | |||
16 | |||
17 | class Recipe(models.Model): | ||
18 | |||
19 | title = CharField(max_length=100) | ||
20 | description = TextField(blank=True, null=True) | ||
21 | servings = IntegerField(blank=True, null=True) | ||
22 | instructions = TextField() | ||
23 | oven_temp = IntegerField(blank=True, null=True) | ||
24 | cook_time = IntegerField(blank=True, null=True) | ||
25 | prep_time = IntegerField(blank=True, null=True) | ||
26 | |||
27 | |||
28 | def __unicode__(self): | ||
29 | return self.title | ||
30 | |||
31 | |||
32 | class Ingredient(models.Model): | ||
33 | |||
34 | name = CharField(max_length=100, unique=True) | ||
35 | |||
36 | def __unicode__(self): | ||
37 | return self.name | ||
38 | |||
39 | |||
40 | class RecipeIngredient(models.Model): | ||
41 | |||
42 | ingredient = ForeignKey(Ingredient) | ||
43 | units = ForeignKey(Unit) | ||
44 | quantity = FloatField() | ||
45 | recipe = ForeignKey(Recipe) | ||
46 | |||
47 | |||
48 | class UnitAdmin(ModelAdmin): | ||
49 | |||
50 | list_display = ('abbreviation', 'name') | ||
51 | |||
52 | |||
53 | class IngredientInline(TabularInline): | ||
54 | |||
55 | model = RecipeIngredient | ||
56 | |||
57 | |||
58 | class RecipeAdmin(ModelAdmin): | ||
59 | |||
60 | list_display = ('title',) | ||
61 | inlines = (IngredientInline,) | ||
62 | |||
63 | |||
64 | class IngredientAdmin(ModelAdmin): | ||
65 | |||
66 | list_display = ('name',) | ||
67 | |||
68 | |||
69 | admin.site.register(Unit, UnitAdmin) | ||
70 | admin.site.register(Ingredient, IngredientAdmin) | ||
71 | admin.site.register(Recipe, RecipeAdmin) | ||