from django.contrib import admin
from .models import Aliment, Journee, Repas, CompositionRepas

@admin.register(Aliment)
class AlimentAdmin(admin.ModelAdmin):
    list_display = ('nom', 'categorie', 'portion_standard')
    list_filter = ('categorie',)
    search_fields = ('nom',)
    ordering = ('categorie', 'nom')

class CompositionRepasInline(admin.TabularInline):
    model = CompositionRepas
    extra = 1

@admin.register(Repas)
class RepasAdmin(admin.ModelAdmin):
    list_display = ('type_repas', 'journee', 'heure')
    list_filter = ('type_repas', 'journee__date')
    inlines = [CompositionRepasInline]

class RepasInline(admin.StackedInline):
    model = Repas
    extra = 0

@admin.register(Journee)
class JourneeAdmin(admin.ModelAdmin):
    list_display = ('date', 'user', 'type_journee')
    list_filter = ('type_journee', 'date')
    inlines = [RepasInline]
    ordering = ('-date',)

@admin.register(CompositionRepas)
class CompositionRepasAdmin(admin.ModelAdmin):
    list_display = ('repas', 'aliment', 'nombre_portions')
    list_filter = ('aliment__categorie',)
