2007/3/6, limodou <[EMAIL PROTECTED]>: > > I think signals will be easier, if you also want to record delete > information of a record, you can also hook pre_delete, the pseudo code > is: > > from django.db.models import signals > > def pre_save(sender, instance, signal, *args, **kwargs): > if instance.id: #update > state = 'change' > old_record = serder.objects.get(id=instance.id) #because the > instance has been changed, so you should get the unchanged record > first > result = #compre old_record and instance > else: > state = 'add' > result = #format instance > WriteLog(state, result) > > def pre_delete(sender, instance, signal, *args, **kwargs): > state = 'delete' > result = #format instance > WriteLog(state, result) > > dispatcher.connect(pre_save , signal=signals.pre_save) > dispatcher.connect(pre_delete , signal=signals.pre_delete) >
I'm really interested in this elegant solution. I want to log actions in database from many objects and many applications in my project and I don't know if it's feasible easily with signals. If yes, where did I have to put this code? Documentation on signals is a bit short... even if mercurityde whitepaper is a great help (http://www.mercurytide.com/whitepapers/django-signals/). Thanks, David --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---