mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 21:45:41 +00:00
feat: add user management viewset and sync module to API routes
This commit is contained in:
35
sync/signals.py
Normal file
35
sync/signals.py
Normal 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__}")
|
||||
Reference in New Issue
Block a user