bgneal@323: """ bgneal@323: Models for the ygroup application, which is a read-only archive of messages bgneal@323: from the old Yahoo Group. bgneal@323: """ bgneal@1035: from django.core.urlresolvers import reverse bgneal@323: from django.db import models bgneal@323: bgneal@323: bgneal@323: class Thread(models.Model): bgneal@323: title = models.CharField(max_length=255) bgneal@323: creation_date = models.DateTimeField() bgneal@323: bgneal@323: # denormalized fields to reduce database hits bgneal@323: poster = models.CharField(max_length=128) bgneal@323: post_count = models.IntegerField(blank=True, default=0) bgneal@323: page = models.IntegerField(blank=True, default=1) bgneal@323: bgneal@323: class Meta: bgneal@323: ordering = ('creation_date', ) bgneal@323: bgneal@323: def __unicode__(self): bgneal@323: return u'Thread %d, %s' % (self.pk, self.title) bgneal@323: bgneal@323: def get_absolute_url(self): bgneal@1035: return reverse('ygroup-thread_view', args=[self.pk]) bgneal@323: bgneal@323: bgneal@323: class Post(models.Model): bgneal@323: thread = models.ForeignKey(Thread, null=True, blank=True, bgneal@323: on_delete=models.SET_NULL, related_name='posts') bgneal@323: title = models.CharField(max_length=255) bgneal@323: creation_date = models.DateTimeField() bgneal@323: poster = models.CharField(max_length=128) bgneal@323: msg = models.TextField() bgneal@323: bgneal@323: # precomputed URL to this post in the parent thread for efficiency bgneal@572: thread_url = models.URLField(blank=True) bgneal@323: bgneal@323: class Meta: bgneal@323: ordering = ('creation_date', ) bgneal@323: verbose_name = 'yahoo group post' bgneal@323: verbose_name_plural = 'yahoo group posts' bgneal@323: bgneal@323: def __unicode__(self): bgneal@323: return u'Post %d, %s' % (self.pk, self.title) bgneal@323: bgneal@323: def get_absolute_url(self): bgneal@1035: return reverse('ygroup-post_view', kwargs={'pk': str(self.pk)}) bgneal@323: bgneal@323: def search_title(self): bgneal@323: return self.title bgneal@323: bgneal@323: def search_summary(self): bgneal@323: return self.msg