summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas NoƩ <nicolas@niconoe.eu>2018-05-03 14:31:31 +0200
committerTim Graham <timograham@gmail.com>2018-05-07 10:07:45 -0400
commitc4158d050f43bb65aad224f4cf7ae56d9e630445 (patch)
tree227ec6aad842b5ebfa96e4ec5bf1398c69ce7c3e
parent523e04dfebf622b922579c3daf139368c4e16031 (diff)
Fixed #29370 -- Added choices to LogEntry.action_flag field.
-rw-r--r--django/contrib/admin/migrations/0003_logentry_add_action_flag_choices.py20
-rw-r--r--django/contrib/admin/models.py8
-rw-r--r--tests/admin_utils/test_logentry.py7
3 files changed, 34 insertions, 1 deletions
diff --git a/django/contrib/admin/migrations/0003_logentry_add_action_flag_choices.py b/django/contrib/admin/migrations/0003_logentry_add_action_flag_choices.py
new file mode 100644
index 0000000000..a041a9de0e
--- /dev/null
+++ b/django/contrib/admin/migrations/0003_logentry_add_action_flag_choices.py
@@ -0,0 +1,20 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('admin', '0002_logentry_remove_auto_add'),
+ ]
+
+ # No database changes; adds choices to action_flag.
+ operations = [
+ migrations.AlterField(
+ model_name='logentry',
+ name='action_flag',
+ field=models.PositiveSmallIntegerField(
+ choices=[(1, 'Addition'), (2, 'Change'), (3, 'Deletion')],
+ verbose_name='action flag',
+ ),
+ ),
+ ]
diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py
index 2f8ecc88df..c7bac4061e 100644
--- a/django/contrib/admin/models.py
+++ b/django/contrib/admin/models.py
@@ -13,6 +13,12 @@ ADDITION = 1
CHANGE = 2
DELETION = 3
+ACTION_FLAG_CHOICES = (
+ (ADDITION, _('Addition')),
+ (CHANGE, _('Change')),
+ (DELETION, _('Deletion')),
+)
+
class LogEntryManager(models.Manager):
use_in_migrations = True
@@ -50,7 +56,7 @@ class LogEntry(models.Model):
object_id = models.TextField(_('object id'), blank=True, null=True)
# Translators: 'repr' means representation (https://docs.python.org/3/library/functions.html#repr)
object_repr = models.CharField(_('object repr'), max_length=200)
- action_flag = models.PositiveSmallIntegerField(_('action flag'))
+ action_flag = models.PositiveSmallIntegerField(_('action flag'), choices=ACTION_FLAG_CHOICES)
# change_message is either a string or a JSON structure
change_message = models.TextField(_('change message'), blank=True)
diff --git a/tests/admin_utils/test_logentry.py b/tests/admin_utils/test_logentry.py
index 64ff5fec3e..b56b209433 100644
--- a/tests/admin_utils/test_logentry.py
+++ b/tests/admin_utils/test_logentry.py
@@ -253,3 +253,10 @@ class LogEntryTests(TestCase):
proxy_delete_log = LogEntry.objects.latest('id')
self.assertEqual(proxy_delete_log.action_flag, DELETION)
self.assertEqual(proxy_delete_log.content_type, proxy_content_type)
+
+ def test_action_flag_choices(self):
+ tests = ((1, 'Addition'), (2, 'Change'), (3, 'Deletion'))
+ for action_flag, display_name in tests:
+ with self.subTest(action_flag=action_flag):
+ log = LogEntry(action_flag=action_flag)
+ self.assertEqual(log.get_action_flag_display(), display_name)