from django.db import models from accounts.models import BaseModel, IAmPrincipal, IAmPrincipalType from django.db.models.signals import post_save from django.dispatch import receiver from manage_wallets.models import Wallet # Create your models here. class NotificationCategoryChoices(models.TextChoices): GENERAL = "general", "General" TRANSACTION = "transaction", "Transaction" REFERRAL = "referral", "Referral" SUBSCRIPTION = "subscription", "Subscription" EVENT = "event", "Event" PROMOTIONS = "promotions", "Promotions" class PrincipalType(models.TextChoices): EVENT_USER = "event_user", "Event User" EVENT_MANAGER = "event_manager", "Event Manager" BOTH = "both", "Both" class PushNotification(BaseModel): title = models.CharField(max_length=255) notification_category = models.CharField( max_length=50, choices=NotificationCategoryChoices.choices, ) banner_image = models.ImageField( upload_to="push_notification_images/", blank=True, null=True ) principal_type = models.CharField( max_length=50, choices=PrincipalType.choices, ) message = models.TextField() def __str__(self): return self.title class IAmPrincipalNotificationSettings(BaseModel): principal = models.ForeignKey( IAmPrincipal, on_delete=models.CASCADE, related_name="notifications_principal" ) notification_category = models.CharField( max_length=50, choices=NotificationCategoryChoices.choices, ) is_enabled = models.BooleanField(default=True) class Meta: db_table = "iam_principal_notification_settings" def __str__(self): return f"{self.principal.first_name} - {self.notification_category}" class InAppNotification(BaseModel): """ Model for in-app notifications """ principal = models.ForeignKey( IAmPrincipal, on_delete=models.CASCADE, related_name="in_app_notifications" ) title = models.CharField(max_length=255) message = models.TextField() notification_category = models.CharField( max_length=50, choices=NotificationCategoryChoices.choices, ) def __str__(self): return f"{self.title} - {self.notification_category}" class Meta: db_table = "in_app_notifications"