1. Joshua Karjala-Svendsen
  2. parentes


parentes / blog / models.py

import datetime
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
from parentes.content_item_base.models import ContentItemBase
from tinymce.models import HTMLField
from easymode.i18n.decorators import I18n

class Category(models.Model):
    title = models.CharField(max_length=250, help_text='Maximum 250 characters.')
    slug = models.SlugField(unique=True, help_text="Suggested value automatically generated from title. Must be unique")
    description = HTMLField(blank=True)
    class Meta: 
        ordering = ["title"] 
        verbose_name_plural = "Categories"
    def __unicode__(self):
        return self.title
    def get_absolute_url(self):
        return "/blog/categories/%s/" % self.slug
    def get_absolute_feed_url(self):
        return "/blog/feeds/categories/%s/" % self.slug
    def live_post_set(self):
        from parentes.blog.models import Post 
        return self.post_set.filter(status=Post.LIVE_STATUS) 

class Post(ContentItemBase): 
    excerpt = HTMLField(blank=True, help_text="A short summary of the post. Optional.") 
    body = HTMLField() 
    category = models.ForeignKey(Category)  
    def get_absolute_url(self): 
        return ('blog_post_detail', (), { 'year': self.publish.strftime("%Y"),
                                            'month': self.publish.strftime("%b").lower(),
                                            'day': self.publish.strftime("%d"),
                                            'slug': self.slug }) 
    get_absolute_url = models.permalink(get_absolute_url) 

class Link(ContentItemBase):
        description = HTMLField(blank=True)
        url = models.URLField('URL', unique=True) 
        via_name = models.CharField('Via', max_length=250, blank=True, 
                                   help_text='The name of the person whose site you spotted the link on. Optional.') 
        via_url = models.URLField('Via URL', verify_exists=False, blank=True, 
                                  help_text='The URL of the site where you spotted the link. Optional.') 
        def get_absolute_url(self): 
            return ('blog_link_detail', (), 
                        { 'year': self.publish.strftime('%Y'), 
                          'month': self.publish.strftime('%b').lower(), 
                          'day': self.publish.strftime('%d'), 
                          'slug': self.slug }) 
        get_absolute_url = models.permalink(get_absolute_url)