diff options
author | Dan McGee <dan@archlinux.org> | 2012-06-20 17:03:26 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-06-20 17:03:26 -0500 |
commit | bbcbde0197d4862b5acc595b17bc5051780dbc9e (patch) | |
tree | 612a78aae2af1ec9a3aa411712ae95ce6ee9c3f0 /devel/models.py | |
parent | 1b03069f0d9e0397a7ff07404343c9400bbcfa1c (diff) |
Add a last_modified field to user profiles
A behind the scenes field that might be slightly useful.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel/models.py')
-rw-r--r-- | devel/models.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/devel/models.py b/devel/models.py index fd5a0347..fd5df00a 100644 --- a/devel/models.py +++ b/devel/models.py @@ -2,11 +2,12 @@ import pytz from django.db import models +from django.db.models.signals import pre_save from django.contrib.auth.models import User from django_countries import CountryField from .fields import PGPKeyField -from main.utils import make_choice +from main.utils import make_choice, utc_now class UserProfile(models.Model): @@ -44,6 +45,7 @@ class UserProfile(models.Model): allowed_repos = models.ManyToManyField('main.Repo', blank=True) latin_name = models.CharField(max_length=255, null=True, blank=True, help_text="Latin-form name; used only for non-Latin full names") + last_modified = models.DateTimeField(editable=False) class Meta: db_table = 'user_profiles' @@ -96,4 +98,18 @@ class PGPSignature(models.Model): def __unicode__(self): return u'%s → %s' % (self.signer, self.signee) + +def set_last_modified(sender, **kwargs): + '''This will set the 'last_modified' field on the user profile to the + current UTC time when either the profile is updated. For use as a pre_save + signal handler.''' + obj = kwargs['instance'] + if hasattr(obj, 'last_modified'): + obj.last_modified = utc_now() + + +# connect signals needed to keep cache in line with reality +pre_save.connect(set_last_modified, sender=UserProfile, + dispatch_uid="devel.models") + # vim: set ts=4 sw=4 et: |