49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from django.contrib import admin
|
|
|
|
from tracker.models import DoseLog, Medication, PulseReading, ScheduledDose
|
|
|
|
|
|
class ScheduledDoseInline(admin.TabularInline):
|
|
"""Edit a medication's daily doses right 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", "is_active"]
|
|
list_filter = ["is_active", "time_of_day", "medication"]
|
|
|
|
|
|
@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"
|