Consolidate unit handling and use proxy classes.
[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', 'tags'],
42                       'classes': ['collapse']}),
43         ('Yield', {'fields': ['unit', 'value', 'min_value', 'max_value'],
44                    'classes': ['collapse']}),
45         ('Directions', {'fields': ['directions_markdown']}),
46         ]
47     inlines = [IngredientBlockInline]
48
49     list_display = ['name']
50
51
52 admin.site.register(models.Recipe, RecipeAdmin)
53 admin.site.register(models.IngredientBlock, IngredientBlockAdmin)
54 admin.site.register(models.Unit)