Files
goodtimes/manage_notifications/signals.py
2024-03-14 13:48:41 +05:30

17 lines
781 B
Python

from django.db.models.signals import post_save
from django.dispatch import receiver
from manage_wallets.models import Wallet
from .models import IAmPrincipalNotificationSettings, NotificationCategoryChoices
@receiver(post_save, sender=Wallet)
def create_default_notification_settings(sender, instance, created, **kwargs):
if created:
principal = instance.principal
# Assuming NotificationCategoryChoices is a list of tuples as choices for the field
for category in NotificationCategoryChoices:
IAmPrincipalNotificationSettings.objects.create(
principal=principal,
notification_category=category.value, # Assuming category is a tuple and the value is at index 0
is_enabled=True
)