Source

Ochs / news / models.py

Full commit
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

from cms.models import CMSPlugin
from cms.models import Page
from tagging.fields import TagField

from staff.models import Position, Profile, STAFF
from courses.models import Course
from ochs_filebrowser.fields import FileBrowseField

# story status constants
DRAFT = 'D'
READY_EDIT = 'R'
READY_PUBLISH = 'E'
PUBLISHED = 'P'
STATIC = 'S'
REJECTED = 'U'
STORY_STATUS = (
    (DRAFT, 'Draft'),
    (READY_EDIT, 'Ready for Editing'),
    (READY_PUBLISH, 'Ready to Publish'),
    (PUBLISHED, 'Published'),
    (STATIC, 'Static'),
    (REJECTED, 'Rejected'),
)

class StoryNotes(models.Model):
    user = models.ForeignKey(Profile)
    story = models.ForeignKey("Story")
    date_added = models.DateTimeField(auto_now_add=True)
    notes = models.TextField()

    class Meta:
        verbose_name_plural = 'Story Notes'
        #ordering = "-date_added"

    def __unicode__(self):
        return "%s\non %s" % (unicode(self.user), str(self.date_added))

class Story(models.Model):
    headline = models.CharField(max_length=255)
    slug = models.SlugField()
    source = models.CharField(max_length=255, blank=True, null=True, verbose_name="Other Sources")
    section = models.ForeignKey(Page, null=True, limit_choices_to={'publisher_public__isnull': False})
    last_modified = models.DateTimeField(auto_now=True)
    publish_date = models.DateTimeField(blank=True, null=True)
    summary = models.TextField()
    body = models.TextField()
    tags = TagField(null=True, blank=True)
    status = models.CharField(max_length=1, choices=STORY_STATUS, default=DRAFT, db_index=True)
    enable_comments = models.BooleanField(default=True)
    breaking_news = models.BooleanField()
    eyebrow = models.BooleanField(default=False, db_index=True)

    class Meta:
        verbose_name_plural = 'stories'

    def __unicode__(self):
        return self.headline

    def get_photos_for_story(self):
        try:
            return flickr.walk(machine_tags='ochs:%s=%s' % (settings.FLICKR_PREDICATE, self.slug)) 
        except flickrapi.exceptions.FlickrError:
            return []

    def get_absolute_url(self):
        return '/%s' % '/'.join([self.section.get_path(), self.slug])

class StoryLink(models.Model):
    story = models.ForeignKey(Story)
    url = models.URLField(verify_exists=False)
    link_text = models.CharField(max_length=255)
    description = models.TextField(blank=True, null=True)
    last_modified = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.link_text

class Byline(models.Model):
    user = models.ForeignKey(Profile)
    course = models.ForeignKey(Course, blank=True, null=True)
    position = models.ForeignKey(Position, null=True, limit_choices_to={'position__in': STAFF})

    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(editable=False)
    content_object = generic.GenericForeignKey('content_type', 'object_id')

class Poll(models.Model):
    story = models.ForeignKey(Story, blank=True, null=True)
    question = models.TextField()
    last_modified = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.question

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.PositiveIntegerField(default=0)

    def __unicode__(self):
        return self.choice

class PhotoPlugin(CMSPlugin):
    story = models.ForeignKey(Story)

    def __unicode__(self):
        return unicode(self.story)

class StoryPlugin(CMSPlugin):
    story = models.ForeignKey(Story)

    def __unicode__(self):
        return unicode(self.story)