mybuddy/core/admin.py

139 lines
4.6 KiB
Python
Raw Normal View History

2017-08-13 14:48:16 +00:00
# -*- coding: utf-8 -*-
2017-08-11 18:32:02 +00:00
from django.contrib import admin
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
2017-11-10 02:15:09 +00:00
from core import models
2017-08-13 14:48:16 +00:00
2020-02-17 14:16:52 +00:00
class ImportExportResourceBase(resources.ModelResource):
id = fields.Field(attribute='id', column_name='entry_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:22:46 +00:00
class ChildImportExportResource(resources.ModelResource):
class Meta:
model = models.Child
exclude = ('picture', 'slug')
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):
2017-08-18 12:08:23 +00:00
list_display = ('first_name', 'last_name', 'birth_date', 'slug')
2017-08-13 20:15:57 +00:00
list_filter = ('last_name',)
search_fields = ('first_name', 'last_name', 'birth_date')
fields = ['first_name', 'last_name', 'birth_date']
2017-12-01 23:07:08 +00:00
if settings.BABY_BUDDY['ALLOW_UPLOADS']:
fields.append('picture')
resource_class = ChildImportExportResource
2020-02-17 14:16:52 +00:00
class DiaperChangeImportExportResource(ImportExportResourceBase):
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)
2020-02-17 14:22:46 +00:00
class DiaperChangeAdmin(ImportExportMixin, ExportActionMixin,
admin.ModelAdmin):
list_display = ('child', 'time', 'wet', 'solid', 'color')
list_filter = ('child', 'wet', 'solid', 'color')
search_fields = ('child__first_name', 'child__last_name',)
resource_class = DiaperChangeImportExportResource
2020-02-17 14:16:52 +00:00
class FeedingImportExportResource(ImportExportResourceBase):
class Meta:
model = models.Feeding
exclude = ('duration',)
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):
list_display = ('start', 'end', 'duration', 'child', 'type', 'method',
'amount')
list_filter = ('child', 'type', 'method',)
search_fields = ('child__first_name', 'child__last_name', 'type',
'method',)
resource_class = FeedingImportExportResource
2020-02-17 14:16:52 +00:00
class NoteImportExportResource(ImportExportResourceBase):
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):
list_display = ('time', 'child', 'note',)
list_filter = ('child',)
search_fields = ('child__last_name',)
resource_class = NoteImportExportResource
2020-02-17 14:16:52 +00:00
class SleepImportExportResource(ImportExportResourceBase):
class Meta:
model = models.Sleep
exclude = ('duration',)
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):
list_display = ('start', 'end', 'duration', 'child', 'nap')
list_filter = ('child',)
search_fields = ('child__first_name', 'child__last_name',)
resource_class = SleepImportExportResource
2020-02-17 14:16:52 +00:00
class TemperatureImportExportResource(ImportExportResourceBase):
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):
2019-05-17 04:33:26 +00:00
list_display = ('child', 'temperature', 'time',)
list_filter = ('child',)
search_fields = ('child__first_name', 'child__last_name', 'temperature',)
resource_class = TemperatureImportExportResource
2019-05-17 04:33:26 +00:00
2017-11-10 02:15:09 +00:00
@admin.register(models.Timer)
class TimerAdmin(admin.ModelAdmin):
list_display = ('name', 'child', 'start', 'end', 'duration', 'active',
'user')
list_filter = ('child', 'active', 'user')
search_fields = ('child__first_name', 'child__last_name', 'name', 'user')
2020-02-17 14:16:52 +00:00
class TummyTimeImportExportResource(ImportExportResourceBase):
class Meta:
model = models.TummyTime
exclude = ('duration',)
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):
list_display = ('start', 'end', 'duration', 'child', 'milestone',)
list_filter = ('child',)
search_fields = ('child__first_name', 'child__last_name', 'milestone',)
resource_class = TummyTimeImportExportResource
2020-02-17 14:16:52 +00:00
class WeightImportExportResource(ImportExportResourceBase):
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):
2017-11-10 02:15:09 +00:00
list_display = ('child', 'weight', 'date',)
list_filter = ('child',)
search_fields = ('child__first_name', 'child__last_name', 'weight',)
resource_class = WeightImportExportResource