diff gpp/forums/models.py @ 102:e67c4dd98db5

Forums: new topic form sprouts boolean fields for sticky and locking if the user has rights. Implemented the locked logic. Fixed a bug where topics where getting out of order (the view_count was bumping the update_date because of auto_now).
author Brian Neal <bgneal@gmail.com>
date Wed, 16 Sep 2009 02:01:57 +0000
parents eb9f99382476
children e94398f5e027
line wrap: on
line diff
--- a/gpp/forums/models.py	Wed Sep 16 00:39:27 2009 +0000
+++ b/gpp/forums/models.py	Wed Sep 16 02:01:57 2009 +0000
@@ -1,6 +1,8 @@
 """
 Models for the forums application.
 """
+import datetime
+
 from django.db import models
 from django.db.models import Q
 from django.contrib.auth.models import User, Group
@@ -121,7 +123,7 @@
 
     # denormalized fields to reduce database hits
     post_count = models.IntegerField(blank=True, default=0)
-    update_date = models.DateTimeField(auto_now=True)
+    update_date = models.DateTimeField()
     last_post = models.OneToOneField('Post', blank=True, null=True,
         related_name='parent_topic')
 
@@ -158,6 +160,14 @@
             return self.post_count - 1
         return 0
 
+    def save(self, *args, **kwargs):
+        if not self.id:
+            now = datetime.datetime.now()
+            self.creation_date = now
+            self.update_date = now
+
+        super(Topic, self).save(*args, **kwargs)
+
 
 class Post(models.Model):
     """