view ygroup/models.py @ 1157:e4f2d6a4b401

Rework S3 connection logic for latest versions of Python 2.7. Had to make these changes for Ubuntu 16.04. Seems backward compatible with production.
author Brian Neal <bgneal@gmail.com>
date Thu, 19 Jan 2017 18:35:53 -0600
parents eeaf387803c6
children
line wrap: on
line source
"""
Models for the ygroup application, which is a read-only archive of messages
from the old Yahoo Group.
"""
from django.core.urlresolvers import reverse
from django.db import models


class Thread(models.Model):
    title = models.CharField(max_length=255)
    creation_date = models.DateTimeField()

    # denormalized fields to reduce database hits
    poster = models.CharField(max_length=128)
    post_count = models.IntegerField(blank=True, default=0)
    page = models.IntegerField(blank=True, default=1)

    class Meta:
        ordering = ('creation_date', )

    def __unicode__(self):
        return u'Thread %d, %s' % (self.pk, self.title)

    def get_absolute_url(self):
        return reverse('ygroup-thread_view', args=[self.pk])


class Post(models.Model):
    thread = models.ForeignKey(Thread, null=True, blank=True,
            on_delete=models.SET_NULL, related_name='posts')
    title = models.CharField(max_length=255)
    creation_date = models.DateTimeField()
    poster = models.CharField(max_length=128)
    msg = models.TextField()

    # precomputed URL to this post in the parent thread for efficiency
    thread_url = models.URLField(blank=True)

    class Meta:
        ordering = ('creation_date', )
        verbose_name = 'yahoo group post'
        verbose_name_plural = 'yahoo group posts'

    def __unicode__(self):
        return u'Post %d, %s' % (self.pk, self.title)

    def get_absolute_url(self):
        return reverse('ygroup-post_view', kwargs={'pk': str(self.pk)})

    def search_title(self):
        return self.title

    def search_summary(self):
        return self.msg