From 5c6f7ead8f23ac76d6650858d1e06d4afb6a2efe Mon Sep 17 00:00:00 2001 From: Caine Date: Wed, 1 Apr 2026 22:48:28 +0100 Subject: Configure settings: add kitchen app, DRF, timezone, allowed hosts --- kitchen/admin.py | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 kitchen/admin.py (limited to 'kitchen/admin.py') 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"] -- cgit v1.2.3