annotate ygroup/models.py @ 917:0365fdbb4d78

Fix app conflict with messages. Django's messages app label conflicts with our messages app. We can't easily rename our label as that will make us rename database tables. Since our app came first we'll just customize Django messages label. For Django 1.7.7 upgrade.
author Brian Neal <bgneal@gmail.com>
date Mon, 06 Apr 2015 20:02:25 -0500
parents ee87ea74d46b
children eeaf387803c6
rev   line source
bgneal@323 1 """
bgneal@323 2 Models for the ygroup application, which is a read-only archive of messages
bgneal@323 3 from the old Yahoo Group.
bgneal@323 4 """
bgneal@323 5 from django.db import models
bgneal@323 6
bgneal@323 7
bgneal@323 8 class Thread(models.Model):
bgneal@323 9 title = models.CharField(max_length=255)
bgneal@323 10 creation_date = models.DateTimeField()
bgneal@323 11
bgneal@323 12 # denormalized fields to reduce database hits
bgneal@323 13 poster = models.CharField(max_length=128)
bgneal@323 14 post_count = models.IntegerField(blank=True, default=0)
bgneal@323 15 page = models.IntegerField(blank=True, default=1)
bgneal@323 16
bgneal@323 17 class Meta:
bgneal@323 18 ordering = ('creation_date', )
bgneal@323 19
bgneal@323 20 def __unicode__(self):
bgneal@323 21 return u'Thread %d, %s' % (self.pk, self.title)
bgneal@323 22
bgneal@323 23 @models.permalink
bgneal@323 24 def get_absolute_url(self):
bgneal@323 25 return ('ygroup-thread_view', [self.id])
bgneal@323 26
bgneal@323 27
bgneal@323 28 class Post(models.Model):
bgneal@323 29 thread = models.ForeignKey(Thread, null=True, blank=True,
bgneal@323 30 on_delete=models.SET_NULL, related_name='posts')
bgneal@323 31 title = models.CharField(max_length=255)
bgneal@323 32 creation_date = models.DateTimeField()
bgneal@323 33 poster = models.CharField(max_length=128)
bgneal@323 34 msg = models.TextField()
bgneal@323 35
bgneal@323 36 # precomputed URL to this post in the parent thread for efficiency
bgneal@572 37 thread_url = models.URLField(blank=True)
bgneal@323 38
bgneal@323 39 class Meta:
bgneal@323 40 ordering = ('creation_date', )
bgneal@323 41 verbose_name = 'yahoo group post'
bgneal@323 42 verbose_name_plural = 'yahoo group posts'
bgneal@323 43
bgneal@323 44 def __unicode__(self):
bgneal@323 45 return u'Post %d, %s' % (self.pk, self.title)
bgneal@323 46
bgneal@323 47 @models.permalink
bgneal@323 48 def get_absolute_url(self):
bgneal@323 49 return ('ygroup-post_view', [], {'pk': self.id})
bgneal@323 50
bgneal@323 51 def search_title(self):
bgneal@323 52 return self.title
bgneal@323 53
bgneal@323 54 def search_summary(self):
bgneal@323 55 return self.msg