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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
from django.contrib import admin
from django.contrib.admin import ModelAdmin, TabularInline
from django.db import models
from django.db.models import CharField, IntegerField, TextField, FloatField
from django.db.models import ForeignKey
class Unit(models.Model):
name = CharField(max_length=100)
abbreviation = CharField(max_length=10, blank=True, null=True)
def __unicode__(self):
return "{0} ({1})".format(self.name, self.abbreviation)
class Recipe(models.Model):
title = CharField(max_length=100)
description = TextField(blank=True, null=True)
servings = IntegerField(blank=True, null=True)
instructions = TextField()
oven_temp = IntegerField(blank=True, null=True)
cook_time = IntegerField(blank=True, null=True)
prep_time = IntegerField(blank=True, null=True)
def __unicode__(self):
return self.title
class Ingredient(models.Model):
name = CharField(max_length=100, unique=True)
def __unicode__(self):
return self.name
class RecipeIngredient(models.Model):
ingredient = ForeignKey(Ingredient)
units = ForeignKey(Unit)
quantity = FloatField()
recipe = ForeignKey(Recipe)
class UnitAdmin(ModelAdmin):
list_display = ('abbreviation', 'name')
class IngredientInline(TabularInline):
model = RecipeIngredient
class RecipeAdmin(ModelAdmin):
list_display = ('title',)
inlines = (IngredientInline,)
class IngredientAdmin(ModelAdmin):
list_display = ('name',)
admin.site.register(Unit, UnitAdmin)
admin.site.register(Ingredient, IngredientAdmin)
admin.site.register(Recipe, RecipeAdmin)
|