Code

Changes between Version 9 and Version 10 of AuditTrail


Ignore:
Timestamp:
10/01/07 11:02:33 (7 years ago)
Author:
gav
Comment:

Fixed maxlength/max_length problem, added I/U distinction on save(), fixed problem with Field.unique.

Legend:

Unmodified
Added
Removed
Modified
  • AuditTrail

    v9 v10  
    5656As you can see, the audit trail is listed with the most recent state first. Each entry also inclues a timestamp when the edit took place. 
    5757 
    58 Saves and deletes are both tracked, and can be filtered on via {{{ Person.history.filter(_audit_change_type='_') }}}.  Do not use underscore, use 'U' for inserts/updates, and 'D' for deletes.  If #4879 lands, then we will be able to distinguish between inserts and updates, and at that point the audit trail will use 'I' for inserts and 'U' for updates. 
     58Saves and deletes are both tracked, and can be filtered on via {{{ Person.history.filter(_audit_change_type='_') }}}.  Do not use underscore, use 'I' for inserts, 'U' for updates, and 'D' for deletes. 
    5959 
    6060ForeignKeys and OneToOneFields are now supported both for saving and accessing the audit data.  However, it does not archive the contents of the ForeignKey table for the appropriate entries at the same time, and will fail if the ForeignKey a given audit entry is related to is deleted (including if you're auditing the ForeignKey table as well, it does not have a way to link the two audit tables together). 
     
    172172                            return field_arr[2] 
    173173 
    174             def _audit(sender, instance): 
     174            def _audit(sender, instance, created): 
    175175                # Write model changes to the audit model. 
    176176                # instance is the current (non-audit) model. 
     
    180180                    kwargs[field.name] = getattr(instance, field.name) 
    181181                if self.opts['save_change_type']: 
    182                     kwargs['_audit_change_type'] = 'U' 
     182                    if created: 
     183                        kwargs['_audit_change_type'] = 'I' 
     184                    else: 
     185                        kwargs['_audit_change_type'] = 'U' 
    183186                for field_arr in model._audit_track: 
    184187                    kwargs[field_arr[0]] = _audit_track(instance, field_arr) 
     
    247250        'Meta': Meta, 
    248251        '_audit_id': models.AutoField(primary_key=True), 
    249         '_audit_timestamp': models.DateTimeField(auto_now_add=True), 
     252        '_audit_timestamp': models.DateTimeField(auto_now_add=True, db_index=True), 
    250253        '_audit__str__': cls.__str__.im_func, 
    251254        '__str__': lambda self: '%s as of %s' % (self._audit__str__(), self._audit_timestamp), 
     
    254257 
    255258    if 'save_change_type' in kwargs and kwargs['save_change_type']: 
    256         attrs['_audit_change_type'] = models.CharField(maxlength=1) 
     259        attrs['_audit_change_type'] = models.CharField(max_length=1) 
    257260 
    258261    if 'show_in_admin' in kwargs and kwargs['show_in_admin']: 
     
    272275        else: 
    273276            attrs[field.name] = copy.copy(field) 
     277            # If 'unique' is in there, we need to remove it, otherwise the index 
     278            # is created and multiple audit entries for one item fail. 
     279            attrs[field.name].unique = False 
    274280 
    275281    for track_field in _track_fields(kwargs['track_fields']):