annotate ygroup/models.py @ 1172:b957e4829a03

Add reCAPTCHA to contact form
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Apr 2018 13:53:05 -0500
parents eeaf387803c6
children
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@1035 5 from django.core.urlresolvers import reverse
bgneal@323 6 from django.db import models
bgneal@323 7
bgneal@323 8
bgneal@323 9 class Thread(models.Model):
bgneal@323 10 title = models.CharField(max_length=255)
bgneal@323 11 creation_date = models.DateTimeField()
bgneal@323 12
bgneal@323 13 # denormalized fields to reduce database hits
bgneal@323 14 poster = models.CharField(max_length=128)
bgneal@323 15 post_count = models.IntegerField(blank=True, default=0)
bgneal@323 16 page = models.IntegerField(blank=True, default=1)
bgneal@323 17
bgneal@323 18 class Meta:
bgneal@323 19 ordering = ('creation_date', )
bgneal@323 20
bgneal@323 21 def __unicode__(self):
bgneal@323 22 return u'Thread %d, %s' % (self.pk, self.title)
bgneal@323 23
bgneal@323 24 def get_absolute_url(self):
bgneal@1035 25 return reverse('ygroup-thread_view', args=[self.pk])
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 def get_absolute_url(self):
bgneal@1035 48 return reverse('ygroup-post_view', kwargs={'pk': str(self.pk)})
bgneal@323 49
bgneal@323 50 def search_title(self):
bgneal@323 51 return self.title
bgneal@323 52
bgneal@323 53 def search_summary(self):
bgneal@323 54 return self.msg