Changes between Version 18 and Version 19 of AuditTrail


Ignore:
Timestamp:
Dec 6, 2008, 1:03:08 PM (16 years ago)
Author:
Jeff Kowalczyk
Comment:

Update AuditTrail(show_in_admin=True), default ModelAdmin support for Django-1.0.x. Put python shebangs back, didn't know they triggered syntax coloring in Trac.

Legend:

Unmodified
Added
Removed
Modified
  • AuditTrail

    v18 v19  
    1010
    1111{{{
     12#!python
    1213from django.db import models
    1314import audit
     
    6364
    6465{{{
     66#!python
    6567def some_callback(instance):
    6668    return `random.randrange(1, 99)` + 'trackable_val'
     
    8183
    8284{{{
     85#!python
    8386>>> p_hist = person.history.all()
    8487[<PersonAudit: John Public as of 2007-08-27 09:29:14>, <PersonAudit: John Public as of 2007-08-27 09:28:57>]
     
    9699
    97100{{{
     101#!python
    98102from django.db import models
    99103
     
    132136from django.db import models
    133137from django.core.exceptions import ImproperlyConfigured
     138from django.contrib import admin
    134139import copy
    135140import re
     
    139144except ImportError:
    140145    settings_audit = None
    141 
    142146value_error_re = re.compile("^.+'(.+)'$")
    143147
     
    158162        def _contribute(sender, **kwargs):
    159163            model = create_audit_model(sender, **self.opts)
     164            if self.opts['show_in_admin']:
     165                # Enable admin integration
     166                # If ModelAdmin needs options or different base class, find
     167                # some way to make the commented code work
     168                #   cls_admin_name = cls.__name__ + 'Admin'
     169                #   clsAdmin = type(cls_admin_name, (admin.ModelAdmin,),{})
     170                #   admin.site.register(cls, clsAdmin)
     171                # Otherwise, register class with default ModelAdmin
     172                admin.site.register(model)
    160173            descriptor = AuditTrailDescriptor(model._default_manager, sender._meta.pk.attname)
    161174            setattr(sender, name, descriptor)
     
    269282        attrs['_audit_change_type'] = models.CharField(max_length=1)
    270283
    271     if 'show_in_admin' in kwargs and kwargs['show_in_admin']:
    272         # Enable admin integration
    273         class Admin:
    274             pass
    275         attrs['Admin'] = Admin
    276 
    277284    # Copy the fields from the existing model to the audit model
    278285    for field in cls._meta.fields:
     
    320327                tracks_found.append(track_item)
    321328            else:
    322 
    323329                tracks_found.append(_build_track_field(track_item))
    324330   
Back to Top