feat: add user management viewset and sync module to API routes

This commit is contained in:
2026-04-04 17:44:05 -03:00
parent 645a5b4093
commit 6c4e95e579
13 changed files with 328 additions and 2 deletions

35
sync/signals.py Normal file
View File

@@ -0,0 +1,35 @@
from django.db.models.signals import post_save, post_delete
from .models import ChangeLog
from products.models import Product
from comandas.models import Comanda, ProductComanda
from orders.models import Order
from clients.models import Client
from categories.models import Categories
from mesas.models import Mesa
from payments.models import Payments
MODELS_TO_TRACK = [
Product, Comanda, ProductComanda, Order, Client, Categories, Mesa, Payments
]
def handle_save(sender, instance, created, **kwargs):
model_name = sender.__name__
ChangeLog.objects.create(
model_name=model_name,
object_id=instance.id,
action='SAVE'
)
def handle_delete(sender, instance, **kwargs):
model_name = sender.__name__
ChangeLog.objects.create(
model_name=model_name,
object_id=instance.id,
action='DELETE'
)
def register_signals():
for model in MODELS_TO_TRACK:
post_save.connect(handle_save, sender=model, dispatch_uid=f"sync_save_{model.__name__}")
post_delete.connect(handle_delete, sender=model, dispatch_uid=f"sync_delete_{model.__name__}")