Fixed #25353 -- Changed LogEntry.action_time to a "date created".

This commit is contained in:
Tim Graham 2015-09-04 11:12:24 -04:00
parent e133b55943
commit d5bac7e449
3 changed files with 48 additions and 5 deletions

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.utils import timezone
class Migration(migrations.Migration):
dependencies = [
('admin', '0001_initial'),
]
# No database changes; removes auto_add and adds default/editable.
operations = [
migrations.AlterField(
model_name='logentry',
name='action_time',
field=models.DateTimeField(
verbose_name='action time',
default=timezone.now,
editable=False,
),
),
]

View File

@ -5,6 +5,7 @@ from django.contrib.admin.utils import quote
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import NoReverseMatch, reverse
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.translation import ugettext, ugettext_lazy as _
@ -17,16 +18,23 @@ class LogEntryManager(models.Manager):
use_in_migrations = True
def log_action(self, user_id, content_type_id, object_id, object_repr, action_flag, change_message=''):
e = self.model(
None, None, user_id, content_type_id, smart_text(object_id),
object_repr[:200], action_flag, change_message
self.model.objects.create(
user_id=user_id,
content_type_id=content_type_id,
object_id=smart_text(object_id),
object_repr=object_repr[:200],
action_flag=action_flag,
change_message=change_message,
)
e.save()
@python_2_unicode_compatible
class LogEntry(models.Model):
action_time = models.DateTimeField(_('action time'), auto_now=True)
action_time = models.DateTimeField(
_('action time'),
default=timezone.now,
editable=False,
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
models.CASCADE,

View File

@ -2405,6 +2405,16 @@ class AdminViewStringPrimaryKeyTest(TestCase):
edited_obj = logentry.get_edited_object()
self.assertEqual(logentry.object_id, str(edited_obj.pk))
def test_logentry_save(self):
""""
LogEntry.action_time is a timestamp of the date when the entry was
created. It shouldn't be updated on a subsequent save().
"""
logentry = LogEntry.objects.get(content_type__model__iexact="modelwithstringprimarykey")
action_time = logentry.action_time
logentry.save()
self.assertEqual(logentry.action_time, action_time)
def test_deleteconfirmation_link(self):
"The link from the delete confirmation page referring back to the changeform of the object should be quoted"
response = self.client.get(reverse('admin:admin_views_modelwithstringprimarykey_delete', args=(quote(self.pk),)))