Configure settings: add kitchen app, DRF, timezone, allowed hosts
This commit is contained in:
@@ -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"]
|
||||
Reference in New Issue
Block a user