Rewrite to Django from scratch. Now it's much more user-friendly.
[cookbook.git] / cookbook / admin.py
diff --git a/cookbook/admin.py b/cookbook/admin.py
new file mode 100644 (file)
index 0000000..cb6a1b1
--- /dev/null
@@ -0,0 +1,55 @@
+from django import forms
+from django.contrib import admin
+from django.db import models as django_models
+
+import models
+
+
+class IngredientInline (admin.TabularInline):
+    model = models.Ingredient
+    extra = 0
+
+
+class IngredientBlockAdmin (admin.ModelAdmin):
+    fieldsets = [
+        (None, {'fields': ['name']}),
+        ('Directions', {'fields': ['directions_markdown'],
+                        'classes': ['collapse']}),
+        ]
+    inlines = [IngredientInline]
+
+    list_display = ['name', 'recipe']
+    extra = 0
+
+
+class IngredientBlockInline (admin.TabularInline):
+    model = models.IngredientBlock
+    fieldsets = [
+        (None, {'fields': ['name']}),
+        ]
+    inlines = [IngredientInline]
+
+    list_display = ['name']
+    extra = 0
+    show_edit_link = True  # https://code.djangoproject.com/ticket/13163
+    # work around 13163
+    #template = 'admin/edit_inline/tabular-13163.html'
+
+class RecipeAdmin (admin.ModelAdmin):
+    fieldsets = [
+        (None, {'fields': ['name']}),
+        ('Metadata', {'fields': ['author', 'source', 'url', 'x_yield', 'tags'],
+                      'classes': ['collapse']}),
+        ('Directions', {'fields': ['directions_markdown']}),
+        ]
+    inlines = [IngredientBlockInline]
+
+    list_display = ['name']
+
+
+admin.site.register(models.Recipe, RecipeAdmin)
+admin.site.register(models.IngredientBlock, IngredientBlockAdmin)
+admin.site.register(models.Amount)
+admin.site.register(models.Unit)
+admin.site.register(models.UnitSystem)
+admin.site.register(models.UnitType)