django-reversion-compare is an extension to django-reversion that provides a history compare view to compare two versions of a model which is under reversion.
Comparing model versions is not a easy task. Maybe there are different view how this should looks like.
This project will gives you a generic way to see whats has been changed.
Many parts are customizable by overwrite methods or subclassing, see above.
Installation
Just use:
pip install django-reversion-compare
Setup
Add reversion_compare to INSTALLED_APPS in your settings.py, e.g.:
Inherit from CompareVersionAdmin instead of VersionAdmin to get the comparison feature.
admin.py e.g.:
from django.contrib import admin
from reversion_compare.admin import CompareVersionAdmin
from my_app.models import ExampleModel
@admin.register(ExampleModel)
class ExampleModelAdmin(CompareVersionAdmin):
pass
If you're using an existing third party app, then you can add patch django-reversion-compare into
its admin class by using the reversion_compare.helpers.patch_admin() method. For example, to add
version control to the built-in User model:
from reversion_compare.helpers import patch_admin
patch_admin(User)
e.g.: Add django-cms Page model:
Works well with
Use together with django-reversion-compare: extensions, drivers, servers and companion tools.
django-reversionPythie’s Index: 73An extension to the Django web framework that provides version control for model instances.2M downloads/mo
from cms.models.pagemodel import Page
from reversion_compare.helpers import patch_admin
# Patch django-cms Page Model to add reversion-compare functionality:
patch_admin(Page)
Customize
It's possible to change the look for every field or for a entire field type.
You must only define a methods to your admin class with this name scheme:
"compare_%s" % field_name
"compare_%s" % field.get_internal_type()
If there is no method with this name scheme, the fallback_compare() method will be used.
An example for specifying a compare method for a model field by name:
class YourAdmin(CompareVersionAdmin):
def compare_foo_bar(self, obj_compare):
""" compare the foo_bar model field """
return "%r <-> %r" % (obj_compare.value1, obj_compare.value2)
and example using patch_admin with custom version admin class:
patch_admin(User, AdminClass=YourAdmin)
Class Based View
Beyond the Admin views, you can also create a Class Based View for displaying and comparing version
differences. This is a single class-based-view that either displays the list of versions to select
for an object or displays both the versions and their differences (if the versions to be compared
have been selected). This class can be used just like a normal DetailView:
More information about this can be found in DocString of:
The make run-test-server test project contains a Demo, use the links under:
HistoryCompareDetailView Examples:
Screenshots
Here some screenshots of django-reversion-compare:
How to select the versions to compare:
from v0.1.0: DateTimeField compare (last update), TextField compare (content) with small changes and a ForeignKey compare (child model instance was added):
from v0.1.0: Same as above, but the are more lines changed in TextField and the ForeignKey relation was removed:
Example screenshot from v0.3.0: a many-to-many field compare (friends, hobbies):
In the first line, the m2m object has been changed.
line 2: A m2m object was deleted
line 3: A m2m object was removed from this entry (but not deleted)
line 4: This m2m object has not changed
create developer environment
We use manage_django_project, so you just need to clone the sources and call manage.py to start hacking.
e.g.:
~$ git clone https://codeberg.org/jedie/django-reversion-compare.git
~$ cd django-reversion-compare
# Just call manage.py and the magic happen:
~/django-reversion-compare$ ./manage.py
# start local dev. web server:
~/django-reversion-compare$ ./manage.py run_dev_server
# run tests:
~/django-reversion-compare$ ./manage.py test
# or with coverage
~/django-reversion-compare$ ./manage.py coverage
# or via tox:
~/django-reversion-compare$ ./manage.py tox p
GitHub suspendedmy account sometime in late August 2026 !
There was no warning beforehand, nor any explanation of the reasons afterwards.
Since then, I have had no access or control over my data on GitHub.
All my projects and everything about me have completely disappeared.
Everything just results in a 404 "Not Found" error page.
2012-05-09 - add example models for many-to-many compare
2012-05-09 - Add compare of many-to-many fields
2012-05-09 - make ForeignKey(User) optional
2012-05-09 - Add admin classes for django-reversion models, too.
2012-05-09 - cleanup
2012-05-09 - more info in debug()
2012-05-08 - mark paragraphs in google-diff-match-patch are IMHO needlessly
2012-05-08 - remove patch_admin(), it's in django-reversion.
2012-05-08 - misspelled
2012-05-08 - add info about google-diff-match-patch
2012-05-08 - bugfix: this should only be used for developing ;)
2012-05-08 - ignore .settings
2012-05-08 - add django, django-reversion as requires in setup.py
2012-05-08 - chmod +x
2012-05-08 - more examples
2012-05-08 - README, LICENSE...
2012-05-08 - change README
2012-05-08 - change screenshots
2012-05-08 - Use field.verbose_name and display field.help_text if exists
2012-05-08 - Use a generic add/remove. Now only for ForeignKey and FileField
2012-05-08 - change debug
2012-05-08 - display revision comment.
2012-05-08 - Add genereic ForeignKey compare.
2012-05-08 - remove date time overwrite
2012-05-08 - add info how to test
2012-05-08 - Split BaseCompareVersionAdmin and CompareVersionAdmin: CompareVersionAdmin should store predefined compare methods.
2012-05-08 - use and instead of "span class"
2012-05-08 - add default username/email
2012-05-08 - rename test app
2012-05-08 - first usable stage
2012-05-08 - setup test project
2012-05-08 - add project
2012-05-08 - update MANIFEST, gitignore
2012-05-08 - change homepage
2012-05-08 - undelete the test_project
2012-05-08 - start collecting all needed code for begining a seperat project.
2012-05-07 - Add two ways to define own compage methods: "compare_%s" % field_name or "compare_%s" % field.get_internal_type()
2012-05-07 - better docstring
2012-05-07 - cleanup the helper stuff and remove pygments: Use google-diff-match-patch if installed. Fallback: ndiff with a simple highlight.
2012-05-07 - * moved the compare stuff from VersionAdmin into CompareVersionAdmin * Add compare_fields and compare_exclude * Make it more flexible: Admin class can define own methods for every field to compare the difference
2012-05-07 - changed TABs to spaces
2012-05-07 - TABs to spaces
2012-05-07 - * The compare view can be disabled/enabled by set compare to None or to a callable object. * Insert compare submit button only, if there are at least two versions
2012-05-07 - move the "make compare" stuff into helpers.
2012-05-07 - Compare always the newest one with the older one
2012-05-07 - change the compare method to a per-field-diff
2012-03-02 - Added locale for pt_BR (Brazilian Portuguese)
2012-02-29 - Removing outdated blog link.
2012-02-15 - Adding in fix for issue #128 - tests (CreateInitialRevisionsTest and VersionAdminTest) failing
2012-02-10 - Possible fix for #104
2012-02-09 - Fixing error in parent revision recovery.
2012-02-05 - Separing out do_revert into a separate helper function called safe_revert. Fixes #83.
2012-02-04 - Decoupling model db and reversion db in get_deleted method
2012-02-03 - Refactoring multi-db support to use set_db and get_db methods.
2012-01-31 - Quote/unquote admin urls
2012-01-31 - Throwing RegistrationError if VersionAdmin is used with a proxy model.
2012-01-30 - Allow object pks to have slashes in them
2011-12-17 - Added in experimental VersionMetaAdmin class.
2011-12-07 - Sending a list of fields to serialize when serializing models.
2011-12-07 - Fixing pull request #116
2011-12-07 - Fixed issue 110 (testCreateInitialRevisions fails for models with initial_data)
2011-11-21 - Fix 78411523 to work with Python 2.5 which doesn't know about class decorators (PEP 3129)
2011-11-18 - Skip test on admin integration if django.contrib.admin is not activated
2011-11-14 - Found a way around peeking into the model state for multi-db support. yay!
2011-11-14 - Made modifications to multi-db support to be a bit more consistent throughout the API to encourage use of the 'db' through out instead of depending on the model private state. Although there are two exceptions to this when using signals, since we don't control how our API gets called here.
2011-11-13 - Adding support for multiple db
2011-11-10 - Allow non-ASCII text in diffs.
2011-11-09 - Increment supported Django version for django-1.4 branch
2011-11-07 - InlineAdminFormSet has a different __init__ in Django 1.4
2011-11-04 - Fixed reversion admin for django 1.4
2011-10-28 - Do not follow hidden foreign keys
2011-10-26 - Updating setup.py version number.
2011-10-26 - Updating for 1.5.1 release.
2011-10-26 - Fixing #41 VersionAdmin.init does not handle inline models with a OneToOneField
2011-10-26 - Fixed #95: RegistrationError with GenericRelation
2011-10-26 - Removed error if request finishes with open revision.
2011-10-26 - Fixing random formatting errors, and unused imports.
2011-10-24 - Check for GenericInlineModelAdmin first, so it gets picked up
2011-10-24 - Remove ipdb
2011-10-24 - Import InlineModelAdmin from the right place
2011-10-24 - check for InlineModelAdmin subclasses rather than TabularInline and StackedInline
2011-10-17 - Fix django version warning with multiple versions
2011-10-17 - fixed typo in RevisionManage._pre_delete_receiver docstring
2011-10-17 - Added norwegian translation.
2011-10-13 - Enabling one-to-one fields to be used with the indexed speedups
2011-10-07 - Added in tests for fix to recover list generation.
2011-10-07 - Fixing error in recovering deleted revisions.
2011-09-28 - Updated the french translation.
2011-09-28 - Fixed translation in recover_form template to be coherent with other templates.
2011-09-04 - Added in more admin hacks to make revert work with inline files.
2011-09-04 - Added in admin hacks that seem to fix related file issues.
2011-09-04 - Added in support for nested RevisionMiddleware. Just in case that randomly happens.
2011-09-04 - Updating admin integration to use new reversion API
2011-09-04 - Added in warning if incorrect version of Django is detected.
2011-09-04 - Fixing typo in doctests.
2011-09-04 - Added in tests for complete admin created / update / revert / recover lifecycle.
2011-09-04 - Added in some tests for VersionAdmin
2011-09-04 - Added in test for revert delete with a delete flag in the revision.
2011-09-04 - Updating doc comments with deprecation notices.
2011-09-04 - Making the create_revision decorator also work as a context manager.
2011-09-02 - Minor docstring corrections.
2011-09-02 - Fixing spelling error.
2011-09-02 - Added in tests for fields and exclude registration params.
2011-09-02 - Refactored patch tests
2011-09-02 - Added in tests for ignoring duplicates.
2011-09-02 - Added in tests for meta.
2011-09-02 - Added in tests for multi table inheritance.
2011-09-02 - Updated tests to disallow proxy models. They're fundamentally broken with django-reversion.
2011-09-02 - Added in tests for proxy model API useage.
2011-09-02 - Added in tests for proxy model registration
2011-09-02 - Added in test for one-to-many follows with revert deletes.
2011-09-02 - Added in test for reverse relationship following
2011-09-02 - Removed admin jsi8n hack
2011-09-02 - Removed some deprecated methods from the admin.
2011-09-02 - Added in more deprecation warnings.
2011-09-01 - Updating TODO list.
2011-09-01 - Fixing typo for deprecated.
2011-09-01 - Added in test for revision revert and delete.
2011-09-01 - Added in test for revision revert.
2011-09-01 - Added in test for version revert.
2011-09-01 - Using property decorators.
2011-09-01 - Removing superfluous errors module.
2011-09-01 - Added in tests for follow relationships.
2011-09-01 - Added in tests for revision middleware.
2011-09-01 - Added in tests for invalidated revisions.
2011-09-01 - Renamed revisions.revision to revisions.default_revision_manager
2011-09-01 - Added in tests for low level API useage.
2011-09-01 - Moving old model manager-based api methods to revision manager.
2011-09-01 - Added in warnings about pending deprications.
2011-09-01 - Cleaned up test code a little.
2011-09-01 - Added in tests for createinitialrevisions command.
2011-09-01 - Added in tests for new registration paradigm.
2011-09-01 - Adding in framework for new tests.
2011-09-01 - Fixing reversion tests.
2011-08-31 - Added in fixes for middleware.
2011-08-31 - Reviewing tests for registration logic.
2011-08-31 - Simplifying followed relations logic.
2011-08-31 - Replacing a list comprehension with a generator expression.
2011-08-31 - Whitespace fix.
2011-08-31 - Added in slug for individual revision managers, and improved efficiency of createinitialrevisions command.
2011-08-31 - Moved amputated ./manage.py file back into the test_project
2011-08-31 - Renamed top-level create_on_success decorator to create_revision.
2011-08-31 - Fairly large refactor of the revision management backend.
2011-08-31 - Cleaning up the codebase a little.
2011-08-26 - Removed some accidentally-included test files.
2011-08-21 - Switching back to sqlite3 backend for testing.
2011-08-21 - Added in fix for tests in sqlite3
2011-08-21 - Seriously improving performance of Version.get_deleted() for models with integer primary keys.
2011-08-21 - Added in test for ordering of loading deleted models.
2011-08-21 - Fixing error in detecting integer primary key on model.
2011-08-21 - Optimizing sort for deleted models.
2011-08-21 - Quicker createinitialrevisions for models with string primary keys.
2011-08-21 - Slightly more efficient list comprehension.
2011-08-20 - Making migration 0004 clean up revisions that refere to content types that no longer exist.
2011-08-20 - Added in GenericForeignKey for Version object.
2011-08-20 - Correcting a minor typo in the README file.
2011-08-20 - Updating README file to warn people about database migrations.
2011-08-20 - Updated changelog.
2011-08-20 - Updated tests to allow for code with and without speedups
2011-08-20 - Adding in tests for models with string primary keys.
2011-08-20 - Added in speedup for createinitialrevisions.
2011-08-20 - Added in speedup for looking up all deleted objects of a given type.
2011-08-20 - Added in speedup for looking up a deleted version of an object.
2011-08-20 - Added in speedup for looking up versions for an object.
2011-08-20 - Added in support for indexed speedups. Currently this is write-only.
2011-08-20 - Added stricter checks for open revisions in the request machinery. It should be impossible, but someone could potentally break something using the low level API, and this will make it fail noisily rather than silently.
2011-08-20 - Fixing issue #66: Object IDs with special characters
2011-08-16 - Renaming style param to cleanup for generating diffs.
2011-08-16 - Cleaning up doc strings for new style parameter in patch helpers.
2011-08-15 - FIX attr value, it SHOWS an TypeError when the value is different to STR, now the value is forced to 'str' to fix it
2011-08-15 - Addign support to identify "Semantic" or "Efficiency" cleanup
2011-07-15 - allow to run createinitialrevisions on Models (verbose names) containing non-ascii chars
2011-07-07 - Removing hyphen from missing users in object_history view.
2011-06-21 - Bugfix: Username is optional in model.
2011-05-25 - Putting in a hack to fix issue #55 - South Breaks Tests in test.py. The real fix needs to be done in South, as per http://south.aeracode.org/ticket/520
2011-05-25 - Added in fix for issue #60 - Problems with the serialization of custom Fields
2011-05-25 - Better fix for excluded file fields.
2011-05-10 - Fix for excluded FileFields
2011-05-06 - delete files marked as deleted when revert is called with delete=True
2011-04-27 - Including readme in distribution.
2011-04-27 - Updated changelog and download URL.
2011-04-27 - Added in version number for 1.4 release.
2011-04-25 - Removed the years and months options from deleterevisions, and corrected some human-readable feedback from the command.
2011-04-25 - Fixed issue #48: Update change_list template to duplicate less code for Django 1.3
2011-04-22 - Added in optional babel support. This makes reversion play nicer with Ththe Debian packaging system.
2011-04-07 - A few code style change for reversion template patch. Nothing major.
2011-04-01 - Give the recover/revert renderer enough context to know what it's doing. This lets users override all of change_form/revision_form/recover_form with a single template.
2011-04-01 - Allow per-app and per-model overriding of some form templates. Specifically, revision_list, revision_form, and recover_form. This follows the same algorithm as Django uses for most of its admin forms.
2011-03-31 - Fixed small errors in French translations.
2011-03-31 - Revert commit of bad changes to translations (f3adc34889e3b7e8536f794bf15993edf6ccbfea).
2011-03-29 - Removed wrapper around file fields. This is no longer required in Django 1.3
2011-03-29 - Added in fix for revert delete=True functionality.
2011-03-29 - Added in test for broken revert delete=True functionality.
2011-03-25 - Added in corect version number
2011-03-22 - Added a hasattr() check in middleware to handle the case where request has no user attribute defined.
2011-03-21 - Updated Polish translation.
2011-03-14 - Updating setup.py to ensure that migrations are packaged with the egg.
2011-03-11 - Making admin work properly with new version type flag
2011-03-11 - Whitespace tweak
2011-03-11 - Fixed bug with following revisions
2011-03-11 - Added in fix for issue #41 - VersionAdmin.init does not handle inline models with a OneToOneField
2011-03-11 - Minor foobar in the new settings.
2011-03-11 - Added in migration for schema change
2011-03-11 - Adding in south migrations
2011-03-11 - Adding in tests to check for stat gathering
2011-03-11 - Removing a sqlite file. Why was that in there anyway?
2011-03-11 - Removed old manager module, to prevent cyclic imports
2011-03-11 - Added in new settings and manage.py from django 1.3
2011-03-11 - Provisional working version for reversion version flags
2011-03-11 - First attempt at adding version type flag
2011-03-05 - Updating download URL for pypi
2011-03-05 - Updating version number for pypi
2011-03-05 - Updating changelog for 1.3.3 release
2011-02-22 - Fixed one serious typo (a minus in order_by) and small cleanups in deleterevisions command.
2011-02-22 - Added the keep options. Removed unnecessary versions deletions (Django take care of it).
2011-02-16 - Added in partial fix for issue #33. Still have error with not recovering files.
2011-02-12 - Lots of refactoring and cleanup. Removed a loop of queries. Added no-confirmation flag and more verbose messages.
2011-02-05 - Fixed date query in apps/models query.
2011-02-05 - Lot of fixes, improved messages, fixed typos.
2011-02-04 - Added draft version of the deleterevisons command.
2011-02-02 - Cleaning up a bit of whitespace after merge.
2011-01-23 - Expanding reversed urls in reversion.admin to account for AdminSite objects with alternate name attribute
2011-01-21 - Tweaked new --comment option for createinitialrevision to thread through the comment option rather than store in self.
2011-01-21 - Added in extra option for createinitialrevisions command.
2011-01-13 - Fixed minor bug in new foreign key resolution code.
2011-01-12 - Updated revert method to be a bit more persistant with regard to database integrity errors, and to report failures to the user.
2010-11-08 - Correcting spelling mistake in doc comments.
2010-11-05 - Temporary disabled some tests that give error with MySQL.
2010-11-04 - Change sdtout.write by print in createinitialrevision command to avoid UnicodeEncodeError in certain context when the model verbose name have non-ASCII characters. Not sure it's a good fix in the long term?
2010-11-02 - Added test to prevent saving a new revision if there's no change.
2010-10-22 - Added in better download URL that PyPi should hopefully recognize
2010-10-22 - Updated setup.py for new release
2010-10-22 - Updated changelog for 1.3.2 release.
2010-10-12 - Added Polish translation.
2010-10-01 - Added french locale
2010-09-16 - Using unicode field fallback in diff helpers.
2010-09-03 - diff helpers can choke on fields with null=True since diff-match-patch expects to receive only strings, not None
2010-09-08 - Added in tests for custom serialization format
2010-09-08 - Added in tests for restricted registration fields
2010-09-08 - Added in unit tests for ManyToMany field following.
2010-09-08 - Added in recover and revert tests for ForeignKey and OneToMany relationships
2010-09-08 - Added in query tests for ForeignKey and OneToMany relationships
2010-09-08 - Cleaning up some unused imports
2010-09-08 - Added in test for model recover.
2010-09-08 - Added in test for model revert.
2010-09-08 - Added in unit tests for reversion deleted object queries
2010-09-08 - Added in unit tests for reversion queries.
2010-09-08 - Added in more unit tests.
2010-09-08 - Replacing old doc tests with unit tests.
2010-09-08 - Added in test model and integrated with patch tests.
2010-09-08 - Made the manager.get_deleted() method more scaleable, at the expense of some performance. This also fixes sqlite max query size errors.
2010-09-08 - Fixed comment
2010-09-08 - Made the createinitialrevision management command more scaleable, at the expense of some performance. Now it actually works in sqlite for large model sets. Fixes issue #7 http://github.com/etianen/django-reversion/issues#issue/7
2010-08-23 - Removed some unneccessary imports.
2010-08-23 - Added some dependencies from old management command.
2010-08-23 - Removed old post_syncdb hook, which wasn't playing nice with other 3rd party apps.
2010-08-23 - Renamed new management command.
2010-08-23 - Tweaked formating to fit project code style (pedantic)
2010-08-14 - new management command for initial reverisons for all or specified apps
2010-08-06 - Tweaking readme formatting
2010-08-06 - Added in links to new project site on GitHub.
2010-07-08 - Silly whitespace fix.
2010-07-08 - Added markdown formatting to readme and CHANGELOG for better github integration.
2010-07-08 - Added in CHANGELOG
2010-07-08 - Added in fix for issue 68: DoesNotExist exception with follows and OneToOneFields
2010-07-08 - Removed some Python 2.3 fallbacks.
2010-05-31 - Changing version number, after fighting with Google Code.
2010-05-31 - Moved metadata to project root
2010-05-31 - Modified setup.py for 1.3 release
2010-05-06 - Putting in the patch from issue 62 - InlineForms break revert
2010-05-06 - Fixed issue 65 - VersionAdmin does not support read-only fields
2010-05-06 - Updated README file to be more hip.
2010-04-01 - Updated admin code to fit with Django trunk. Didn't seem to be any issues with the old stuff, but it's always good to keep in sync.
2010-04-01 - Now using decorators in admin.py, as there is no need to support Python 2.3 for Django 1.2
2010-03-03 - Including licence in sdist.
2010-03-01 - Changed reference to model.id to model.pk.
2010-02-26 - Revision middleware always closes the revision.
2010-02-26 - Fixing issue 29.
2010-02-26 - Adding fix for issue 59. Untested in postgres.
2010-02-26 - Added workaround for importing admin modules when one app depends on another.
2010-01-29 - Updated setup.py to include new management package.
2010-01-29 - Bugfix on post_sycdb hook.
2010-01-29 - Moved revcheck to a post_syncdb hook.
2010-01-29 - Added in revcheck code from Marco marcoberi@gmail.com. Still needs tests and potentially moving to a post sync-db hook.
2010-01-21 - Added templatetags package to setup.py.
2010-01-07 - Now using JSON as default serialization format for smaller storage requirements.
2010-01-06 - Removed recover deleted button from popup changelist.
2009-12-21 - Fixed issue 54: Reversion unit tests always register django.contrib.auth.models.User, even if app code has already done so.
2009-12-17 - Added in a better hack for fixing the js18n relative URL.
2009-12-10 - Fixed issue 52: UnicodeDecodeError in revision_view
2009-12-10 - Added hebrew translation.
2009-11-13 - Fixed Issue 49: Passing unsaved models to reversion using api, still creates version of the model in the db
2009-11-13 - Fixed issue 48: ct_fk_field_name is always object_id. Use ct_fk_field.name instead
2009-10-29 - Fixed error with wrapped add_view and change_view.
2009-10-28 - Removed superfluous print statement.
2009-10-28 - Using a url resolver in object_history view.
2009-10-28 - Added locale files to pypy package.
2009-10-16 - Added Russian translations.
2009-10-11 - Updated setup.py for impending release.
2009-10-06 - Better test settings.
2009-10-06 - Fixed error with recovering related inline models.
2009-10-06 - Switched to exclusive use of url confs in VersionAdmin and templates.
2009-10-04 - Fixed error with inline data (issue 33)
2009-10-04 - Corrected errors with proxy models.
2009-09-29 - Added license and readme files.
2009-08-30 - Added transaction rollbacks to tests to play nicely with postgres.
2009-08-30 - Doctests no longer require diff_match_patch.
2009-08-30 - list_editable is now supported!
2009-08-30 - Added in the updated Italian translation strings.
2009-07-23 - Removed Eclipse metadata
2009-07-23 - Final commit before the 1.1.2 release.
2009-07-16 - Modified setup.py for upcoming release.
2009-07-16 - Added default serialization format property for reversion admin.
2009-07-09 - Standard Django advice is to not use null=True on character data fields.
2009-07-01 - Added a hook for creating the initial form data used for the recover form.
2009-06-19 - Fixed issue 30: KeyError raised if related model's ForeignKey to parent has editable=False
2009-05-19 - Fixed problem with proxy model registration.