notifications/apps/emails/models.py
Sayyid Hamid Mahdavi 5ac1715adb bulk push
2025-09-02 20:12:20 +03:30

37 lines
1.2 KiB
Python

from django.db import models
from oauth2_provider.settings import oauth2_settings
from apps.users.models import User
from utils.models import BaseModel
from django.utils.translation import gettext_lazy as _
class EmailQuerySet(models.QuerySet):
pass
class Email(BaseModel):
class StateChoices(models.IntegerChoices):
INIT = 0, _('init')
START = 1, _('Start')
DONE = 2, _('done')
TIMEOUT = 3, _('timeout')
FAILED = 4, _('failed')
user = models.ForeignKey(User, on_delete=models.PROTECT)
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL, on_delete=models.PROTECT,
related_name='+', null=True, blank=True)
title = models.CharField(max_length=128)
message = models.TextField()
priority = models.IntegerField(default=5)
extras = models.JSONField(default=dict)
stats = models.IntegerField(default=StateChoices.INIT, choices=StateChoices.choices)
# bulk = models.ForeignKey("BulkEmail", null=True, blank=True, on_delete=models.PROTECT)
objects = EmailQuerySet.as_manager()
def send_email(self):
from apps.emails.tasks import send_email
send_email.delay(str(self.uuid))