from django.db import models import uuid from . import ModelOperation class ModelLog(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) users = models.ManyToManyField('CustomUser', 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)