set ModelLog transactions as atomic

sync
Laurent 9 months ago
parent 5922e1b6ec
commit 8b8e0eb9d5
  1. 3
      sync/models/model_log.py
  2. 19
      sync/signals.py

@ -24,6 +24,9 @@ class ModelLog(models.Model):
device_id = models.CharField(max_length=200, blank=True, null=True) device_id = models.CharField(max_length=200, blank=True, null=True)
count = models.IntegerField(default=0) count = models.IntegerField(default=0)
class Meta:
ordering = ['-date']
def formatted_time(self): def formatted_time(self):
return self.date.strftime('%H:%M:%S.%f') return self.date.strftime('%H:%M:%S.%f')

@ -120,15 +120,16 @@ def save_model_log_if_possible(instance, signal, created, device_id):
def save_model_log(users, model_operation, model_name, model_id, store_id, device_id): def save_model_log(users, model_operation, model_name, model_id, store_id, device_id):
model_log = ModelLog() with transaction.atomic():
model_log.operation = model_operation model_log = ModelLog()
model_log.model_name = model_name model_log.operation = model_operation
model_log.model_id = model_id model_log.model_name = model_name
model_log.store_id = store_id model_log.model_id = model_id
model_log.device_id = device_id model_log.store_id = store_id
# model_log.date = timezone.now() model_log.device_id = device_id
model_log.save() # model_log.date = timezone.now()
model_log.users.set(users) model_log.save()
model_log.users.set(users)
# print(f'ML users = {len(users)}') # print(f'ML users = {len(users)}')
# existing_log = ModelLog.objects.filter(users__in=users, model_id=model_id, operation=model_operation).first() # existing_log = ModelLog.objects.filter(users__in=users, model_id=model_id, operation=model_operation).first()

Loading…
Cancel
Save