""" Административная панель для уведомлений. """ from django.contrib import admin from django.utils.html import format_html from .models import Notification, NotificationPreference, NotificationTemplate, ParentChildNotificationSettings @admin.register(Notification) class NotificationAdmin(admin.ModelAdmin): """Административная панель для уведомлений.""" list_display = [ 'title', 'recipient', 'notification_type', 'channel', 'status_badge', 'priority', 'created_at' ] list_filter = [ 'notification_type', 'channel', 'priority', 'is_read', 'is_sent', 'created_at' ] search_fields = [ 'title', 'message', 'recipient__email', 'recipient__first_name', 'recipient__last_name' ] date_hierarchy = 'created_at' readonly_fields = ['created_at', 'sent_at', 'read_at'] def status_badge(self, obj): """Отображение статуса.""" if obj.is_read: return format_html( 'Прочитано' ) elif obj.is_sent: return format_html( 'Отправлено' ) else: return format_html( 'Ожидает' ) status_badge.short_description = 'Статус' @admin.register(NotificationPreference) class NotificationPreferenceAdmin(admin.ModelAdmin): """Административная панель для настроек уведомлений.""" list_display = [ 'user', 'enabled', 'email_enabled', 'telegram_enabled', 'in_app_enabled', 'quiet_hours_enabled' ] list_filter = ['enabled', 'email_enabled', 'telegram_enabled', 'quiet_hours_enabled'] search_fields = ['user__email', 'user__first_name', 'user__last_name'] @admin.register(NotificationTemplate) class NotificationTemplateAdmin(admin.ModelAdmin): """Административная панель для шаблонов уведомлений.""" list_display = ['notification_type', 'is_active', 'updated_at'] list_filter = ['is_active'] search_fields = ['notification_type'] @admin.register(ParentChildNotificationSettings) class ParentChildNotificationSettingsAdmin(admin.ModelAdmin): """Административная панель для настроек уведомлений родителя для детей.""" list_display = ['parent', 'child', 'enabled', 'updated_at'] list_filter = ['enabled', 'created_at'] search_fields = [ 'parent__user__email', 'parent__user__first_name', 'parent__user__last_name', 'child__user__email', 'child__user__first_name', 'child__user__last_name' ] readonly_fields = ['created_at', 'updated_at'] raw_id_fields = ['parent', 'child']