from django.contrib import admin from tracker.models import ( DailyNote, DoseLog, GlobalNote, Medication, PulseReading, ReminderSent, ScheduledDose, ) class ScheduledDoseInline(admin.TabularInline): """Edit a medication's daily doses (and their reminder times) on the medication page.""" model = ScheduledDose extra = 1 @admin.register(Medication) class MedicationAdmin(admin.ModelAdmin): list_display = ["name", "is_active", "schedule_summary"] list_filter = ["is_active"] search_fields = ["name"] inlines = [ScheduledDoseInline] @admin.display(description="Schedule") def schedule_summary(self, obj: Medication) -> str: doses = obj.scheduled_doses.filter(is_active=True) if not doses: return "—" return ", ".join( f"{d.amount} {d.get_time_of_day_display().lower()}" for d in doses ) @admin.register(ScheduledDose) class ScheduledDoseAdmin(admin.ModelAdmin): list_display = ["medication", "time_of_day", "amount", "reminder_time", "is_active"] list_filter = ["is_active", "time_of_day", "medication"] @admin.register(ReminderSent) class ReminderSentAdmin(admin.ModelAdmin): """Read-only trail of which reminders went out, for when one seems to be missing.""" list_display = ["date", "scheduled_dose", "sent_at"] list_filter = ["date"] def has_add_permission(self, request): return False def has_change_permission(self, request, obj=None): return False @admin.register(DoseLog) class DoseLogAdmin(admin.ModelAdmin): """The history. Day-to-day ticking off happens on the Today page.""" list_display = ["date", "scheduled_dose", "taken", "taken_at"] list_filter = ["taken", "date", "scheduled_dose__medication"] date_hierarchy = "date" @admin.register(PulseReading) class PulseReadingAdmin(admin.ModelAdmin): list_display = ["date", "bpm", "notes"] date_hierarchy = "date" @admin.register(DailyNote) class DailyNoteAdmin(admin.ModelAdmin): """The journal. Day-to-day writing happens on the Today page.""" list_display = ["date", "preview", "updated_at"] date_hierarchy = "date" search_fields = ["body"] @admin.display(description="Note") def preview(self, obj: DailyNote) -> str: return obj.body[:80] @admin.register(GlobalNote) class GlobalNoteAdmin(admin.ModelAdmin): """The one shared note. It can be edited here, but never added or deleted.""" list_display = ["__str__", "updated_at"] def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None): return False