summaryrefslogtreecommitdiff
path: root/kitchen/admin.py
diff options
context:
space:
mode:
authorCaine <caine@jihakuz.xyz>2026-04-01 22:48:28 +0100
committerCaine <caine@jihakuz.xyz>2026-04-01 22:48:28 +0100
commit5c6f7ead8f23ac76d6650858d1e06d4afb6a2efe (patch)
tree32741d68101e2a4d301f38d83de74e97349c8fcd /kitchen/admin.py
parent40cc3de3e4d017f9241eecb35cd7854e9aec48fe (diff)
Configure settings: add kitchen app, DRF, timezone, allowed hosts
Diffstat (limited to 'kitchen/admin.py')
-rw-r--r--kitchen/admin.py122
1 files changed, 122 insertions, 0 deletions
diff --git a/kitchen/admin.py b/kitchen/admin.py
new file mode 100644
index 0000000..661c931
--- /dev/null
+++ b/kitchen/admin.py
@@ -0,0 +1,122 @@
+from django.contrib import admin
+from .models import (
+ Tag,
+ Ingredient,
+ PantryItem,
+ MetaRecipe,
+ Slot,
+ SlotOption,
+ MetaRecipeBase,
+ Recipe,
+ RecipeIngredient,
+ CookLog,
+ ShoppingListItem,
+)
+
+
+@admin.register(Tag)
+class TagAdmin(admin.ModelAdmin):
+ list_display = ["name"]
+ search_fields = ["name"]
+
+
+@admin.register(Ingredient)
+class IngredientAdmin(admin.ModelAdmin):
+ list_display = ["name", "default_unit", "shelf_life_days", "tag_list"]
+ list_filter = ["tags"]
+ search_fields = ["name", "aliases"]
+ filter_horizontal = ["tags"]
+
+ def tag_list(self, obj):
+ return ", ".join(t.name for t in obj.tags.all())
+
+ tag_list.short_description = "Tags"
+
+
+@admin.register(PantryItem)
+class PantryItemAdmin(admin.ModelAdmin):
+ list_display = [
+ "ingredient",
+ "quantity",
+ "unit",
+ "location",
+ "stored_date",
+ "expiry_date",
+ "is_staple",
+ ]
+ list_filter = ["location", "is_staple"]
+ search_fields = ["ingredient__name"]
+ list_editable = ["quantity"]
+
+
+# --- Meta-Recipe inlines ---
+
+
+class SlotOptionInline(admin.TabularInline):
+ model = SlotOption
+ extra = 1
+ autocomplete_fields = ["ingredient"]
+
+
+class SlotInline(admin.TabularInline):
+ model = Slot
+ extra = 1
+ show_change_link = True # Link to slot detail to manage options
+
+
+class MetaRecipeBaseInline(admin.TabularInline):
+ model = MetaRecipeBase
+ extra = 1
+ autocomplete_fields = ["ingredient"]
+
+
+@admin.register(MetaRecipe)
+class MetaRecipeAdmin(admin.ModelAdmin):
+ list_display = ["name", "default_servings", "prep_time_mins", "cook_time_mins", "gear_needed"]
+ search_fields = ["name"]
+ inlines = [SlotInline, MetaRecipeBaseInline]
+
+
+@admin.register(Slot)
+class SlotAdmin(admin.ModelAdmin):
+ list_display = ["meta_recipe", "name", "required", "max_choices", "option_count"]
+ list_filter = ["meta_recipe", "required"]
+ inlines = [SlotOptionInline]
+
+ def option_count(self, obj):
+ return obj.options.count()
+
+ option_count.short_description = "Options"
+
+
+# --- Fixed Recipe inlines ---
+
+
+class RecipeIngredientInline(admin.TabularInline):
+ model = RecipeIngredient
+ extra = 1
+ autocomplete_fields = ["ingredient"]
+
+
+@admin.register(Recipe)
+class RecipeAdmin(admin.ModelAdmin):
+ list_display = ["name", "servings", "prep_time_mins", "cook_time_mins", "source_url"]
+ search_fields = ["name"]
+ inlines = [RecipeIngredientInline]
+
+
+# --- Cook Log & Shopping ---
+
+
+@admin.register(CookLog)
+class CookLogAdmin(admin.ModelAdmin):
+ list_display = ["date", "meta_recipe", "recipe", "servings"]
+ list_filter = ["date"]
+ date_hierarchy = "date"
+
+
+@admin.register(ShoppingListItem)
+class ShoppingListItemAdmin(admin.ModelAdmin):
+ list_display = ["__str__", "quantity", "unit", "reason", "added_date", "checked"]
+ list_filter = ["checked"]
+ list_editable = ["checked"]