summaryrefslogtreecommitdiff
path: root/packages/models.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-05-03 14:41:00 -0500
committerDan McGee <dan@archlinux.org>2011-05-03 14:41:00 -0500
commitef9faf4414edd013755431fb2e78d9e46d448cb8 (patch)
tree25e43d635950fecddaac46b9f87ad702561b8212 /packages/models.py
parente6415c1a8be9032367c782546eb155fd6b7c23e1 (diff)
Add a created date to package relations
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages/models.py')
-rw-r--r--packages/models.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/models.py b/packages/models.py
index 79e8abca..a950bddb 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -1,5 +1,7 @@
+from datetime import datetime
+
from django.db import models
-from django.db.models.signals import post_save
+from django.db.models.signals import pre_save, post_save
from django.contrib.auth.models import User
class PackageRelation(models.Model):
@@ -18,6 +20,7 @@ class PackageRelation(models.Model):
pkgbase = models.CharField(max_length=255)
user = models.ForeignKey(User, related_name="package_relations")
type = models.PositiveIntegerField(choices=TYPE_CHOICES, default=MAINTAINER)
+ created = models.DateTimeField(editable=False)
def get_associated_packages(self):
# TODO: delayed import to avoid circular reference
@@ -109,7 +112,15 @@ def remove_inactive_maintainers(sender, instance, created, **kwargs):
type=PackageRelation.MAINTAINER)
maint_relations.delete()
+def set_created_field(sender, **kwargs):
+ # We use this same callback for both Isos and Tests
+ obj = kwargs['instance']
+ if not obj.created:
+ obj.created = datetime.utcnow()
+
post_save.connect(remove_inactive_maintainers, sender=User,
dispatch_uid="packages.models")
+pre_save.connect(set_created_field, sender=PackageRelation,
+ dispatch_uid="packages.models")
# vim: set ts=4 sw=4 et: