From d5fac0d146885e6fb8a1d822ca49b0bb79ff56d6 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 29 May 2015 00:06:06 +0100 Subject: [PATCH] Add translating choice fields to correct values. --- RIGS/versioning.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/RIGS/versioning.py b/RIGS/versioning.py index 1065aa3c..e1e96793 100644 --- a/RIGS/versioning.py +++ b/RIGS/versioning.py @@ -16,6 +16,7 @@ import simplejson from reversion.models import Version from django.contrib.contenttypes.models import ContentType # Used to lookup the content_type from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.db.models import ForeignKey, IntegerField from RIGS import models, forms import datetime @@ -35,8 +36,21 @@ def model_compare(oldObj, newObj, excluded_keys=[]): class FieldCompare(object): def __init__(self, field=None, old=None, new=None): self.field = field - self.old = old - self.new = new + self._old = old + self._new = new + + def display_value(self, value): + if isinstance(self.field, IntegerField) and len(self.field.choices) > 0: + return [x[1] for x in self.field.choices if x[0] == value][0] + return value + + @property + def old(self): + return self.display_value(self._old) + + @property + def new(self): + return self.display_value(self._new) changes = []