2017-08-13 14:48:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-08-11 18:32:02 +00:00
|
|
|
from django.contrib import admin
|
2017-11-19 01:57:29 +00:00
|
|
|
from django.conf import settings
|
2017-08-11 18:32:02 +00:00
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
from import_export import fields, resources
|
|
|
|
from import_export.admin import ImportExportMixin, ExportActionMixin
|
2020-02-16 23:58:49 +00:00
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
from core import models
|
2022-03-08 11:55:50 +00:00
|
|
|
from core.forms import TagAdminForm
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class ImportExportResourceBase(resources.ModelResource):
|
2022-02-10 00:00:30 +00:00
|
|
|
id = fields.Field(attribute="id")
|
|
|
|
child = fields.Field(attribute="child_id", column_name="child_id")
|
|
|
|
child_first_name = fields.Field(attribute="child__first_name", readonly=True)
|
|
|
|
child_last_name = fields.Field(attribute="child__last_name", readonly=True)
|
2020-02-17 14:16:52 +00:00
|
|
|
|
2020-02-17 18:34:31 +00:00
|
|
|
class Meta:
|
|
|
|
clean_model_instances = True
|
2022-02-10 00:00:30 +00:00
|
|
|
exclude = ("duration",)
|
2020-02-17 18:34:31 +00:00
|
|
|
|
2020-02-17 14:22:46 +00:00
|
|
|
|
2022-04-04 22:52:10 +00:00
|
|
|
class BMIImportExportResource(ImportExportResourceBase):
|
|
|
|
class Meta:
|
|
|
|
model = models.BMI
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(models.BMI)
|
|
|
|
class BMIAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
|
|
|
list_display = (
|
|
|
|
"child",
|
|
|
|
"bmi",
|
|
|
|
"date",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-04-04 22:52:10 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"bmi",
|
|
|
|
)
|
|
|
|
resource_class = BMIImportExportResource
|
|
|
|
|
|
|
|
|
2020-02-16 23:58:49 +00:00
|
|
|
class ChildImportExportResource(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = models.Child
|
2022-02-10 00:00:30 +00:00
|
|
|
exclude = ("picture", "slug")
|
2020-02-16 23:58:49 +00:00
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.Child)
|
2020-02-17 14:16:52 +00:00
|
|
|
class ChildAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-02-10 00:00:30 +00:00
|
|
|
list_display = ("first_name", "last_name", "birth_date", "slug")
|
|
|
|
list_filter = ("last_name",)
|
|
|
|
search_fields = ("first_name", "last_name", "birth_date")
|
|
|
|
fields = ["first_name", "last_name", "birth_date"]
|
|
|
|
if settings.BABY_BUDDY["ALLOW_UPLOADS"]:
|
|
|
|
fields.append("picture")
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = ChildImportExportResource
|
|
|
|
|
|
|
|
|
2022-03-04 15:39:13 +00:00
|
|
|
class PumpingImportExportResource(ImportExportResourceBase):
|
2022-03-03 03:00:56 +00:00
|
|
|
class Meta:
|
2022-03-04 15:39:13 +00:00
|
|
|
model = models.Pumping
|
2022-03-03 03:00:56 +00:00
|
|
|
|
|
|
|
|
2022-03-04 15:39:13 +00:00
|
|
|
@admin.register(models.Pumping)
|
|
|
|
class PumpingAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-03-03 03:00:56 +00:00
|
|
|
list_display = (
|
2023-06-16 21:07:24 +00:00
|
|
|
"start",
|
|
|
|
"end",
|
|
|
|
"duration",
|
2022-03-03 03:00:56 +00:00
|
|
|
"child",
|
|
|
|
"amount",
|
|
|
|
)
|
|
|
|
list_filter = ("child",)
|
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"amount",
|
|
|
|
)
|
2022-03-04 15:39:13 +00:00
|
|
|
resource_class = PumpingImportExportResource
|
2022-03-03 03:07:16 +00:00
|
|
|
|
2022-03-03 03:00:56 +00:00
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class DiaperChangeImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.DiaperChange
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.DiaperChange)
|
2022-02-10 00:00:30 +00:00
|
|
|
class DiaperChangeAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
|
|
|
list_display = ("child", "time", "wet", "solid", "color")
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "wet", "solid", "color", "tags")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = DiaperChangeImportExportResource
|
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class FeedingImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Feeding
|
2017-08-13 19:51:25 +00:00
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.Feeding)
|
2020-02-17 14:16:52 +00:00
|
|
|
class FeedingAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2023-06-16 21:07:24 +00:00
|
|
|
list_display = (
|
|
|
|
"start",
|
|
|
|
"end",
|
|
|
|
"duration",
|
|
|
|
"child",
|
|
|
|
"type",
|
|
|
|
"method",
|
|
|
|
"amount",
|
|
|
|
)
|
2022-02-10 00:00:30 +00:00
|
|
|
list_filter = (
|
|
|
|
"child",
|
|
|
|
"type",
|
|
|
|
"method",
|
2022-04-04 23:08:33 +00:00
|
|
|
"tags",
|
2022-02-10 00:00:30 +00:00
|
|
|
)
|
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"type",
|
|
|
|
"method",
|
|
|
|
)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = FeedingImportExportResource
|
|
|
|
|
|
|
|
|
2022-04-04 22:52:10 +00:00
|
|
|
class HeadCircumferenceImportExportResource(ImportExportResourceBase):
|
|
|
|
class Meta:
|
|
|
|
model = models.HeadCircumference
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(models.HeadCircumference)
|
|
|
|
class HeadCircumferenceAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
|
|
|
list_display = (
|
|
|
|
"child",
|
|
|
|
"head_circumference",
|
|
|
|
"date",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-04-04 22:52:10 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"head_circumference",
|
|
|
|
)
|
|
|
|
resource_class = HeadCircumferenceImportExportResource
|
|
|
|
|
|
|
|
|
|
|
|
class HeightImportExportResource(ImportExportResourceBase):
|
|
|
|
class Meta:
|
|
|
|
model = models.Height
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(models.Height)
|
|
|
|
class HeightAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
|
|
|
list_display = (
|
|
|
|
"child",
|
|
|
|
"height",
|
|
|
|
"date",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-04-04 22:52:10 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"height",
|
|
|
|
)
|
|
|
|
resource_class = HeightImportExportResource
|
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class NoteImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Note
|
2017-08-13 15:59:14 +00:00
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.Note)
|
2020-02-17 14:16:52 +00:00
|
|
|
class NoteAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-02-10 00:00:30 +00:00
|
|
|
list_display = (
|
|
|
|
"time",
|
|
|
|
"child",
|
|
|
|
"note",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = ("child__last_name",)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = NoteImportExportResource
|
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class SleepImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Sleep
|
2017-08-13 20:48:16 +00:00
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.Sleep)
|
2020-02-17 14:16:52 +00:00
|
|
|
class SleepAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-02-10 00:00:30 +00:00
|
|
|
list_display = ("start", "end", "duration", "child", "nap")
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = SleepImportExportResource
|
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class TemperatureImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Temperature
|
2017-08-13 19:05:44 +00:00
|
|
|
|
|
|
|
|
2019-05-17 04:33:26 +00:00
|
|
|
@admin.register(models.Temperature)
|
2020-02-17 14:16:52 +00:00
|
|
|
class TemperatureAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-02-10 00:00:30 +00:00
|
|
|
list_display = (
|
|
|
|
"child",
|
|
|
|
"temperature",
|
|
|
|
"time",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"temperature",
|
|
|
|
)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = TemperatureImportExportResource
|
2019-05-17 04:33:26 +00:00
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.Timer)
|
2017-08-16 22:33:02 +00:00
|
|
|
class TimerAdmin(admin.ModelAdmin):
|
2022-08-14 20:55:57 +00:00
|
|
|
list_display = ("name", "child", "start", "duration", "user")
|
|
|
|
list_filter = ("child", "user")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = ("child__first_name", "child__last_name", "name", "user")
|
2017-08-16 22:33:02 +00:00
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class TummyTimeImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.TummyTime
|
|
|
|
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
@admin.register(models.TummyTime)
|
2020-02-17 14:16:52 +00:00
|
|
|
class TummyTimeAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-02-10 00:00:30 +00:00
|
|
|
list_display = (
|
|
|
|
"start",
|
|
|
|
"end",
|
|
|
|
"duration",
|
|
|
|
"child",
|
|
|
|
"milestone",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"milestone",
|
|
|
|
)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = TummyTimeImportExportResource
|
|
|
|
|
|
|
|
|
2020-02-17 14:16:52 +00:00
|
|
|
class WeightImportExportResource(ImportExportResourceBase):
|
2020-02-16 23:58:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Weight
|
2017-11-10 02:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(models.Weight)
|
2020-02-17 14:16:52 +00:00
|
|
|
class WeightAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-02-10 00:00:30 +00:00
|
|
|
list_display = (
|
|
|
|
"child",
|
|
|
|
"weight",
|
|
|
|
"date",
|
|
|
|
)
|
2022-04-04 23:08:33 +00:00
|
|
|
list_filter = ("child", "tags")
|
2022-02-10 00:00:30 +00:00
|
|
|
search_fields = (
|
|
|
|
"child__first_name",
|
|
|
|
"child__last_name",
|
|
|
|
"weight",
|
|
|
|
)
|
2020-02-16 23:58:49 +00:00
|
|
|
resource_class = WeightImportExportResource
|
2022-02-15 09:13:35 +00:00
|
|
|
|
2022-02-27 19:36:31 +00:00
|
|
|
|
2022-03-02 20:53:51 +00:00
|
|
|
class TaggedItemInline(admin.StackedInline):
|
|
|
|
model = models.Tagged
|
2022-02-15 09:13:35 +00:00
|
|
|
|
2022-02-27 19:36:31 +00:00
|
|
|
|
2022-04-04 22:44:26 +00:00
|
|
|
class TagImportExportResource(ImportExportResourceBase):
|
|
|
|
class Meta:
|
|
|
|
model = models.Tag
|
|
|
|
|
|
|
|
|
2022-03-02 20:53:51 +00:00
|
|
|
@admin.register(models.Tag)
|
2022-04-04 22:44:26 +00:00
|
|
|
class TagAdmin(ImportExportMixin, ExportActionMixin, admin.ModelAdmin):
|
2022-03-08 11:55:50 +00:00
|
|
|
form = TagAdminForm
|
2022-03-02 20:53:51 +00:00
|
|
|
inlines = [TaggedItemInline]
|
2022-02-15 09:13:35 +00:00
|
|
|
list_display = ["name", "slug", "color", "last_used"]
|
|
|
|
ordering = ["name", "slug"]
|
|
|
|
search_fields = ["name"]
|
|
|
|
prepopulated_fields = {"slug": ["name"]}
|
2022-04-04 22:44:26 +00:00
|
|
|
resource_class = TagImportExportResource
|