Skip to content

Commit

Permalink
update enum class to django text choices (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
given131 authored Nov 8, 2022
1 parent ebd7a5b commit a6b9195
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions backend/notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
from django.db import models
from enum import Enum


# TODO - state definition for notification, notification log, and reservation
class EnumNotifcationStatus(Enum):
class EnumNotifcationStatus(models.TextChoices):
PENDING = 'PENDING'
SENDING = 'SENDING'
SUCCESS = 'SUCCESS'
PARTIAL_SUCCESS = 'PARTIAL_SUCCESS'
FAILURE = 'FAILURE'


class EnumNotificationType(Enum):
class EnumNotificationType(models.TextChoices):
EMAIL = 'EMAIL'
SMS = 'SMS'
API = 'API'


class Notification(models.Model):
message = models.TextField() # TODO - should be changed to foreign key to message
message = models.TextField() # TODO - should be changed to foreign key to message
project = models.ForeignKey('project.Project', on_delete=models.CASCADE)
status = models.CharField(max_length=20, choices=[(tag, tag.value) for tag in EnumNotifcationStatus])
type = models.CharField(max_length=20, choices=[(tag, tag.value) for tag in EnumNotificationType])
status = models.CharField(max_length=20, choices=EnumNotifcationStatus.choices)
type = models.CharField(max_length=20, choices=EnumNotificationType.choices)


class NotificationLog(models.Model):
notification = models.ForeignKey('Notification', on_delete=models.CASCADE)
status = models.CharField(max_length=20, choices=[(tag, tag.value) for tag in EnumNotifcationStatus])
status = models.CharField(max_length=20, choices=EnumNotificationType.choices)
request = models.JSONField()
response = models.JSONField()
created_at = models.DateTimeField(auto_now_add=True)
Expand All @@ -37,5 +36,5 @@ class NotificationLog(models.Model):
class Reservation(models.Model):
notifcation = models.ForeignKey('Notification', on_delete=models.CASCADE)
reserved_at = models.DateTimeField(auto_now_add=True)
status = models.CharField(max_length=20, choices=[(tag, tag.value) for tag in EnumNotifcationStatus])
status = models.CharField(max_length=20, choices=EnumNotifcationStatus.choices)
# TODO - add target user
1 change: 1 addition & 0 deletions backend/notifications/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class NotificationSerializer(serializers.ModelSerializer):
class Meta:
model = Notification
fields = ('id', 'message', 'project', 'status', 'type',)

0 comments on commit a6b9195

Please sign in to comment.