models.py 945 B

1234567891011121314151617181920212223242526
  1. from django.db import models
  2. from .email import send_email_notification
  3. class Notification(models.Model):
  4. created = models.DateField(auto_now_add=True)
  5. project = models.ForeignKey("projects.Project", on_delete=models.CASCADE)
  6. is_sent = models.BooleanField(default=False)
  7. issues = models.ManyToManyField("issues.Issue")
  8. def send_notifications(self):
  9. """ Email only for now, eventually needs to be an extendable system """
  10. send_email_notification(self)
  11. self.is_sent = True
  12. self.save()
  13. class ProjectAlert(models.Model):
  14. """
  15. Example: Send notification when project has 15 events in 5 minutes.
  16. """
  17. project = models.ForeignKey("projects.Project", on_delete=models.CASCADE)
  18. timespan_minutes = models.PositiveSmallIntegerField(blank=True, null=True)
  19. quantity = models.PositiveSmallIntegerField(blank=True, null=True)
  20. created = models.DateTimeField(auto_now_add=True)