Example #1
0
 def adjust_history(self, obj, action='U'):
     '''
     Adjusts the latest entry to accomidate any changes not picked up
     Likely changes are ManyToManyFields
     '''
     delta = self.get_difference(obj)
     if delta:
         ct = ContentType.objects.get_for_model(obj)
         try:
             history = get_active_histories().filter(content_type=ct, 
                                                     object_id=obj.pk).latest()
         except FullHistory.DoesNotExist:
             history = FullHistory(content_object=obj,
                                   request=get_or_create_request(), 
                                   action=action, 
                                   data=dict())
         if history.action == 'C':
             for key, value in delta.items():
                 delta[key] = (value[1],)
         data = history.data
         data.update(delta)
         history.data = data
         history.info = history.create_info()
         history.save()
         self.prepare_initial(obj)
         post_adjust.send(sender=type(obj), 
                          fullhistory=history, 
                          instance=obj)
         return history
     return None