robosats/api/models/notification.py
KoalaSat 1757a9781a
Feat: add notifications api endpoint (#1347)
* Notifications Endpoint

* Fix tests

* CR

* Check tests

* Fix Tests

* Fix Chat

* Remove unused notifications

* Fix chat

* Fix chat

* Fix chat
2024-06-27 16:47:23 +00:00

36 lines
1019 B
Python

# We use custom seeded UUID generation during testing
import uuid
from decouple import config
from api.models import Order, Robot
from django.db import models
from django.utils import timezone
if config("TESTING", cast=bool, default=False):
import random
import string
random.seed(1)
chars = string.ascii_lowercase + string.digits
def custom_uuid():
return uuid.uuid5(uuid.NAMESPACE_DNS, "".join(random.choices(chars, k=20)))
else:
custom_uuid = uuid.uuid4
class Notification(models.Model):
# notification info
created_at = models.DateTimeField(default=timezone.now)
robot = models.ForeignKey(Robot, on_delete=models.CASCADE, default=None)
order = models.ForeignKey(Order, on_delete=models.CASCADE, default=None)
# notification details
title = models.CharField(max_length=240, null=False, default=None)
description = models.CharField(max_length=240, default=None, blank=True)
def __str__(self):
return f"{self.title} {self.description}"