Rewrite to Django from scratch. Now it's much more user-friendly.
[cookbook.git] / cookbook / admin.py
1 from django import forms
2 from django.contrib import admin
3 from django.db import models as django_models
4
5 import models
6
7
8 class IngredientInline (admin.TabularInline):
9     model = models.Ingredient
10     extra = 0
11
12
13 class IngredientBlockAdmin (admin.ModelAdmin):
14     fieldsets = [
15         (None, {'fields': ['name']}),
16         ('Directions', {'fields': ['directions_markdown'],
17                         'classes': ['collapse']}),
18         ]
19     inlines = [IngredientInline]
20
21     list_display = ['name', 'recipe']
22     extra = 0
23
24
25 class IngredientBlockInline (admin.TabularInline):
26     model = models.IngredientBlock
27     fieldsets = [
28         (None, {'fields': ['name']}),
29         ]
30     inlines = [IngredientInline]
31
32     list_display = ['name']
33     extra = 0
34     show_edit_link = True  # https://code.djangoproject.com/ticket/13163
35     # work around 13163
36     #template = 'admin/edit_inline/tabular-13163.html'
37
38 class RecipeAdmin (admin.ModelAdmin):
39     fieldsets = [
40         (None, {'fields': ['name']}),
41         ('Metadata', {'fields': ['author', 'source', 'url', 'x_yield', 'tags'],
42                       'classes': ['collapse']}),
43         ('Directions', {'fields': ['directions_markdown']}),
44         ]
45     inlines = [IngredientBlockInline]
46
47     list_display = ['name']
48
49
50 admin.site.register(models.Recipe, RecipeAdmin)
51 admin.site.register(models.IngredientBlock, IngredientBlockAdmin)
52 admin.site.register(models.Amount)
53 admin.site.register(models.Unit)
54 admin.site.register(models.UnitSystem)
55 admin.site.register(models.UnitType)