]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/question.py
switch to a default sort of active, and "pushed" the active tab to the beggining
[osqa.git] / forum / models / question.py
index 3bf517c6bedbd09903d76660166d4aa054e38710..da8083f6d1407f41d46649fce8593ea59ee3d01d 100644 (file)
@@ -5,7 +5,7 @@ from django.utils.translation import ugettext as _
 question_view = django.dispatch.Signal(providing_args=['instance', 'user'])
 
 class Question(QandA):
-    answer_accepted = models.BooleanField(default=False)
+    accepted_answer = models.OneToOneField('Answer', null=True, related_name="question_accepting")
     closed          = models.BooleanField(default=False)
     closed_by       = models.ForeignKey(User, null=True, blank=True, related_name='closed_questions')
     closed_at       = models.DateTimeField(null=True, blank=True)
@@ -17,7 +17,7 @@ class Question(QandA):
     view_count           = models.IntegerField(default=0)
     favourite_count      = models.IntegerField(default=0)
     last_activity_at     = models.DateTimeField(default=datetime.datetime.now)
-    last_activity_by     = models.ForeignKey(User, related_name='last_active_in_questions')
+    last_activity_by     = models.ForeignKey(User, related_name='last_active_in_questions', null=True)
 
     favorited_by         = models.ManyToManyField(User, through='FavoriteQuestion', related_name='favorite_questions')
 
@@ -34,12 +34,14 @@ class Question(QandA):
 
         return self.title
 
-    def delete(self):
-        super(Question, self).delete()
-        try:
-            ping_google()
-        except Exception:
-            logging.debug('problem pinging google did you register you sitemap with google?')
+    @property
+    def answer_accepted(self):
+        return self.accepted_answer is not None
+
+    def save(self, *args, **kwargs):
+        if not self.last_activity_by:
+            self.last_activity_by = self.author
+        super(Question, self).save(*args, **kwargs)
 
     def update_last_activity(self, user):
         self.last_activity_by = user
@@ -74,9 +76,6 @@ class Question(QandA):
     def get_revision_url(self):
         return reverse('question_revisions', args=[self.id])
 
-    def get_latest_revision(self):
-        return self.revisions.all()[0]
-
     def get_related_questions(self, count=10):
         cache_key = '%s.related_questions:%d:%d' % (settings.APP_URL, count, self.id)
         related_list = cache.get(cache_key)