Skip to content

Commit 7ea4655

Browse files
Nikolaus Schlemmjayvdb
Nikolaus Schlemm
authored andcommitted
integrate with django-reversion-compare to offer a history compare view in admin
1 parent 1d53b25 commit 7ea4655

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

dbtemplates/admin.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
add_template_to_cache)
1111
from dbtemplates.utils.template import check_template_syntax
1212

13-
# Check if django-reversion is installed and use reversions' VersionAdmin
14-
# as the base admin class if yes
15-
if settings.DBTEMPLATES_USE_REVERSION:
13+
# Check if either django-reversion-compare or django-reversion is installed and
14+
# use reversion_compare's CompareVersionAdmin or reversion's VersionAdmin as
15+
# the base admin class if yes
16+
if settings.DBTEMPLATES_USE_REVERSION_COMPARE:
17+
from reversion_compare.admin import CompareVersionAdmin as TemplateModelAdmin
18+
elif settings.DBTEMPLATES_USE_REVERSION:
1619
from reversion.admin import VersionAdmin as TemplateModelAdmin
1720
else:
1821
from django.contrib.admin import ModelAdmin as TemplateModelAdmin # noqa

dbtemplates/conf.py

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class DbTemplatesConf(AppConf):
1111
USE_CODEMIRROR = False
1212
USE_REVERSION = False
13+
USE_REVERSION_COMPARE = False
1314
USE_TINYMCE = False
1415
USE_REDACTOR = False
1516
ADD_DEFAULT_SITE = True
@@ -45,6 +46,13 @@ def configure_use_reversion(self, value):
4546
"use of it in dbtemplates.")
4647
return value
4748

49+
def configure_use_reversion_compare(self, value):
50+
if value and 'reversion_compare' not in settings.INSTALLED_APPS:
51+
raise ImproperlyConfigured("Please add 'reversion_compare' to your "
52+
"INSTALLED_APPS setting to make "
53+
"use of it in dbtemplates.")
54+
return value
55+
4856
def configure_use_tinymce(self, value):
4957
if value and 'tinymce' not in settings.INSTALLED_APPS:
5058
raise ImproperlyConfigured("Please add 'tinymce' to your "

docs/advanced.txt

+9
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,17 @@ Short installation howto
6161
3. Sync your database with ``python manage.py syncdb``
6262
4. Set ``DBTEMPLATES_USE_REVERSION`` setting to ``True``
6363

64+
History compare view
65+
--------------------
66+
67+
You can also use ``dbtemplates`` together with `django-reversion-compare`_ which
68+
provides a history compare view to compare two versions of a model which is under
69+
reversion.
70+
6471
.. _django-reversion: https://github.com/etianen/django-reversion
6572
.. _django-reversion's documentation: https://django-reversion.readthedocs.io/en/latest/
73+
.. _django-reversion-compare: https://github.com/jedie/django-reversion-compare
74+
6675

6776
.. _commands:
6877

docs/settings.txt

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Set to ``False`` by default.
4141

4242
A boolean, if enabled triggers the use of ``django-reversion``.
4343

44+
``DBTEMPLATES_USE_REVERSION_COMPARE``
45+
-----------------------------
46+
47+
A boolean, if enabled triggers the use of ``django-reversion-compare``.
48+
4449
``DBTEMPLATES_MEDIA_PREFIX``
4550
----------------------------
4651

0 commit comments

Comments
 (0)