소스 검색

Fixed #15661 - LogEntry objects have no unicode method

Thanks to Keryn Knight for the report and initial patch, and ShawnMilo for
additional work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16120 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Luke Plant 14 년 전
부모
커밋
f459169170
2개의 변경된 파일33개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      django/contrib/admin/models.py
  2. 21 0
      tests/regressiontests/admin_util/tests.py

+ 12 - 1
django/contrib/admin/models.py

@@ -33,6 +33,17 @@ class LogEntry(models.Model):
     def __repr__(self):
         return smart_unicode(self.action_time)
 
+    def __unicode__(self):
+
+        if self.action_flag == ADDITION:
+            return _('Added "%(object)s".') % {'object': self.object_repr}
+        elif self.action_flag == CHANGE:
+            return _('Changed "%(object)s" - %(changes)s') % {'object': self.object_repr, 'changes': self.change_message}
+        elif self.action_flag == DELETION:
+            return _('Deleted "%(object)s."') % {'object': self.object_repr}
+
+        return_value = _('LogEntry Object')
+
     def is_addition(self):
         return self.action_flag == ADDITION
 
@@ -53,4 +64,4 @@ class LogEntry(models.Model):
         """
         if self.content_type and self.object_id:
             return mark_safe(u"%s/%s/%s/" % (self.content_type.app_label, self.content_type.model, quote(self.object_id)))
-        return None
+        return None

+ 21 - 0
tests/regressiontests/admin_util/tests.py

@@ -235,3 +235,24 @@ class UtilTests(unittest.TestCase):
             label_for_field('guest', Event, return_attr=True),
             ('awesome guest', None),
         )
+
+    def test_logentry_unicode(self):
+        """
+        Regression test for #15661
+        """
+        log_entry = admin.models.LogEntry()
+
+        log_entry.action_flag = admin.models.ADDITION
+        self.assertTrue(
+            unicode(log_entry).startswith('Added ')
+        )
+
+        log_entry.action_flag = admin.models.CHANGE
+        self.assertTrue(
+            unicode(log_entry).startswith('Changed ')
+        )
+
+        log_entry.action_flag = admin.models.DELETION
+        self.assertTrue(
+            unicode(log_entry).startswith('Deleted ')
+        )