diff options
author | Mike Crute <mcrute@gmail.com> | 2013-04-20 11:58:17 -0400 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2013-04-20 11:58:17 -0400 |
commit | 3a8a5dd687e44f4adb9750decd290d36cf9a1772 (patch) | |
tree | 1e5178a10a27e2585d9db1e82f598d5891d2600a | |
parent | 0ce0ee1ef411b3300030cc13a2052e31850fa475 (diff) | |
download | greenbox-3a8a5dd687e44f4adb9750decd290d36cf9a1772.tar.bz2 greenbox-3a8a5dd687e44f4adb9750decd290d36cf9a1772.tar.xz greenbox-3a8a5dd687e44f4adb9750decd290d36cf9a1772.zip |
Split out admin stuff
-rw-r--r-- | recipe/admin.py | 33 | ||||
-rw-r--r-- | recipe/models.py | 35 |
2 files changed, 33 insertions, 35 deletions
diff --git a/recipe/admin.py b/recipe/admin.py new file mode 100644 index 0000000..12bf0fa --- /dev/null +++ b/recipe/admin.py | |||
@@ -0,0 +1,33 @@ | |||
1 | from django.contrib import admin | ||
2 | from recipe.models import Unit, Ingredient, Recipe, RecipeIngredient | ||
3 | |||
4 | |||
5 | class UnitAdmin(admin.ModelAdmin): | ||
6 | |||
7 | list_display = ('name', 'abbreviation') | ||
8 | ordering = ('name',) | ||
9 | |||
10 | |||
11 | class IngredientInline(admin.TabularInline): | ||
12 | |||
13 | model = RecipeIngredient | ||
14 | extra = 12 | ||
15 | |||
16 | |||
17 | class RecipeAdmin(admin.ModelAdmin): | ||
18 | |||
19 | list_display = ('title',) | ||
20 | inlines = (IngredientInline,) | ||
21 | search_fields = ('title',) | ||
22 | prepopulated_fields = { "slug": ("title",) } | ||
23 | |||
24 | |||
25 | class IngredientAdmin(admin.ModelAdmin): | ||
26 | |||
27 | list_display = ('name',) | ||
28 | search_fields = ('name',) | ||
29 | |||
30 | |||
31 | admin.site.register(Unit, UnitAdmin) | ||
32 | admin.site.register(Ingredient, IngredientAdmin) | ||
33 | admin.site.register(Recipe, RecipeAdmin) | ||
diff --git a/recipe/models.py b/recipe/models.py index 548536e..fc611a3 100644 --- a/recipe/models.py +++ b/recipe/models.py | |||
@@ -1,5 +1,4 @@ | |||
1 | from django.db import models | 1 | from django.db import models |
2 | from django.contrib import admin | ||
3 | from django.db.models import fields | 2 | from django.db.models import fields |
4 | 3 | ||
5 | 4 | ||
@@ -53,37 +52,3 @@ class RecipeIngredient(models.Model): | |||
53 | 52 | ||
54 | def __unicode__(self): | 53 | def __unicode__(self): |
55 | return "{0} in {1}".format(self.ingredient.name, self.recipe.title) | 54 | return "{0} in {1}".format(self.ingredient.name, self.recipe.title) |
56 | |||
57 | |||
58 | class UnitAdmin(admin.ModelAdmin): | ||
59 | |||
60 | list_display = ('name', 'abbreviation') | ||
61 | ordering = ('name',) | ||
62 | |||
63 | |||
64 | class IngredientInline(admin.TabularInline): | ||
65 | |||
66 | model = RecipeIngredient | ||
67 | extra = 12 | ||
68 | |||
69 | |||
70 | class RecipeAdmin(admin.ModelAdmin): | ||
71 | |||
72 | list_display = ('title',) | ||
73 | inlines = (IngredientInline,) | ||
74 | search_fields = ('title',) | ||
75 | prepopulated_fields = { "slug": ("title",) } | ||
76 | |||
77 | |||
78 | class IngredientAdmin(admin.ModelAdmin): | ||
79 | |||
80 | list_display = ('name',) | ||
81 | search_fields = ('name',) | ||
82 | |||
83 | |||
84 | try: | ||
85 | admin.site.register(Unit, UnitAdmin) | ||
86 | admin.site.register(Ingredient, IngredientAdmin) | ||
87 | admin.site.register(Recipe, RecipeAdmin) | ||
88 | except admin.sites.AlreadyRegistered: | ||
89 | pass | ||