You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
padelclub_backend/sync/models/model_log.py

30 lines
1.2 KiB

from django.db import models
from django.conf import settings
import uuid
class ModelOperation(models.TextChoices):
POST = 'POST', 'POST'
PUT = 'PUT', 'PUT'
DELETE = 'DELETE', 'DELETE'
GRANT_ACCESS = 'GRANT_ACCESS', 'GRANT_ACCESS'
REVOKE_ACCESS = 'REVOKE_ACCESS', 'REVOKE_ACCESS'
class ModelLog(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='model_logs', blank=True)
model_id = models.UUIDField()
operation = models.CharField(choices=ModelOperation.choices, max_length=50)
date = models.DateTimeField()
model_name = models.CharField(max_length=50)
store_id = models.CharField(max_length=200, blank=True, null=True)
# parent_model_id = models.UUIDField(blank=True, null=True)
# parent_model_name = models.CharField(max_length=50, blank=True, null=True)
def save(self, *args, **kwargs):
# Round microseconds to milliseconds (3 decimal places)
if self.date:
microseconds = round(self.date.microsecond, -3) # Round to nearest thousand
self.date = self.date.replace(microsecond=microseconds)
super().save(*args, **kwargs)