comparison ygroup/models.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/ygroup/models.py@368d731af479
children eeaf387803c6
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 Models for the ygroup application, which is a read-only archive of messages
3 from the old Yahoo Group.
4 """
5 from django.db import models
6
7
8 class Thread(models.Model):
9 title = models.CharField(max_length=255)
10 creation_date = models.DateTimeField()
11
12 # denormalized fields to reduce database hits
13 poster = models.CharField(max_length=128)
14 post_count = models.IntegerField(blank=True, default=0)
15 page = models.IntegerField(blank=True, default=1)
16
17 class Meta:
18 ordering = ('creation_date', )
19
20 def __unicode__(self):
21 return u'Thread %d, %s' % (self.pk, self.title)
22
23 @models.permalink
24 def get_absolute_url(self):
25 return ('ygroup-thread_view', [self.id])
26
27
28 class Post(models.Model):
29 thread = models.ForeignKey(Thread, null=True, blank=True,
30 on_delete=models.SET_NULL, related_name='posts')
31 title = models.CharField(max_length=255)
32 creation_date = models.DateTimeField()
33 poster = models.CharField(max_length=128)
34 msg = models.TextField()
35
36 # precomputed URL to this post in the parent thread for efficiency
37 thread_url = models.URLField(blank=True)
38
39 class Meta:
40 ordering = ('creation_date', )
41 verbose_name = 'yahoo group post'
42 verbose_name_plural = 'yahoo group posts'
43
44 def __unicode__(self):
45 return u'Post %d, %s' % (self.pk, self.title)
46
47 @models.permalink
48 def get_absolute_url(self):
49 return ('ygroup-post_view', [], {'pk': self.id})
50
51 def search_title(self):
52 return self.title
53
54 def search_summary(self):
55 return self.msg