From 59bb64f40972c163aa899cb01c0d7e2e188b56f3 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sat, 17 Dec 2016 14:28:01 +0100 Subject: [PATCH] Fix notifications for ForeignKey fields Instead of reporting the integer value of the foreign key, we should report the text value from the related object. This makes the new submissions more readable, and also makes the system not throw an exception when trying to diff (as integers cannot be diffed). THis seems to have broken around the time of the 1.8 upgrade, just went unnoticed for a long time probably because changing things like which organization owns a news item doesn't happen very often. --- pgweb/util/signals.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pgweb/util/signals.py b/pgweb/util/signals.py index 73e0d9bf..0d51817b 100644 --- a/pgweb/util/signals.py +++ b/pgweb/util/signals.py @@ -46,8 +46,8 @@ def _get_all_notification_fields(obj): return obj.notify_fields else: # Include all field names except specified ones, - # that are "direct" (by get_field_by_name()[2]) - return [n for n in obj._meta.get_all_field_names() if not n in ('approved', 'submitter', 'id', ) and obj._meta.get_field_by_name(n)[2]] + # that are local to this model (not auto created) + return [f.name for f in obj._meta.get_fields() if not f.name in ('approved', 'submitter', 'id', ) and not f.auto_created] def _get_attr_value(obj, fieldname): # see if this is a Many-to-many field. If yes, we want to print @@ -58,7 +58,7 @@ def _get_attr_value(obj, fieldname): return '' # Return the value, or an empty tring if it's NULL (migrated records) - return getattr(obj, fieldname) or '' + return unicode(getattr(obj, fieldname)) or '' def _get_full_text_representation(obj): fieldlist = _get_all_notification_fields(obj) -- 2.39.5