Beispiel #1
0
def attach_db_track_signals():
	model_list = get_all_models()
	track_save = track(action="save")
	track_delete = track(action="delete")
	for model_dict in model_list:
		model = model_dict['model']
		if model_dict['name'] == 'info.models.DBTracker':
			continue
		post_save.connect(track_delete, sender=model)
		post_save.connect(track_save, sender=model)
from library import get_all_models
import models
from django.db.models.signals import post_save

def track(action="not set"):
	def func(sender, **kwargs):
		db_tracker = models.DBTracker()
		db_tracker.model = kwargs['instance'].__class__.__name__
		db_tracker.action = action
		db_tracker.save()
	return func

model_list = get_all_models()
post_func = track(action="post_save")
for model_dict in model_list:
	model = model_dict['model']
	if model_dict['name'] == 'ownmodule.models.DBTracker':
		continue
	post_save.connect(post_func, sender=model)