From 18f764b3aeb2f696fe1837074b3b2ca2515ebeae Mon Sep 17 00:00:00 2001 From: abhisgithub Date: Tue, 12 Jun 2018 18:22:29 +0530 Subject: [PATCH] revision compare for course articles --- Course/admin.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Course/admin.py b/Course/admin.py index 9d6634ae..ac05c775 100644 --- a/Course/admin.py +++ b/Course/admin.py @@ -1,12 +1,31 @@ from django.contrib import admin from mptt.admin import DraggableMPTTAdmin from .models import Course, Topics, Links, TopicArticle +from reversion_compare.admin import CompareVersionAdmin +from reversion_compare.mixins import CompareMixin +from django.db.models import Manager # Register your models here. +_old_compare = CompareMixin.compare + + +def compare(self, obj, version1, version2): + def replace_taggit_field(version_ins): + for fieldname in version_ins.field_dict: + if isinstance(version_ins.field_dict[fieldname], Manager): + version_ins.field_dict[fieldname] = [] + replace_taggit_field(version1) + replace_taggit_field(version2) + return _old_compare(self, obj, version1, version2) + +CompareMixin.compare = compare + +class TopicArticleAdmin(CompareVersionAdmin): + pass admin.site.register(Course) admin.site.register(Links) -admin.site.register(TopicArticle) +admin.site.register(TopicArticle, TopicArticleAdmin)