From f5ddf5a60c7bd454b13eed4f3add71bedfc984c1 Mon Sep 17 00:00:00 2001 From: Scott Duckworth <sduckwo@clemson.edu> Date: Mon, 7 Jul 2014 15:48:19 -0400 Subject: [PATCH] make UserKey.touch() save without updating last_modified --- django_sshkey/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/django_sshkey/models.py b/django_sshkey/models.py index 9d923f7..558add5 100644 --- a/django_sshkey/models.py +++ b/django_sshkey/models.py @@ -26,6 +26,8 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import datetime + from django.db import models from django.contrib.auth.models import User from django.core.exceptions import ValidationError @@ -40,7 +42,7 @@ class UserKey(models.Model): key = models.TextField(max_length=2000) fingerprint = models.CharField(max_length=47, blank=True, db_index=True) created = models.DateTimeField(auto_now_add=True, null=True) - last_modified = models.DateTimeField(auto_now=True, null=True) + last_modified = models.DateTimeField(null=True) last_used = models.DateTimeField(null=True) class Meta: @@ -97,9 +99,14 @@ class UserKey(models.Model): return pubkey.format_pem() raise ValueError("Invalid format") + def save(self, *args, **kwargs): + if kwargs.pop('update_last_modified', True): + self.last_modified = datetime.datetime.now() + super(UserKey, self).save(*args, **kwargs) + def touch(self): - import datetime self.last_used = datetime.datetime.now() + self.save(update_last_modified=False) @receiver(pre_save, sender=UserKey) def send_email_add_key(sender, instance, **kwargs): -- libgit2 0.26.0