Django-Portfolio / demenza_site / blog /

import datetime

from django.db import models
from django.contrib.auth.models import User

from taggit.managers import TaggableManager

class PostManager(models.Manager):
    def get_visible(self):
        return self.get_query_set().filter(, active=True)

class TimeStampedActivate(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    active = models.BooleanField(default=False,
                                 help_text="Controls whether or not this item is visible to the world.")

    class Meta:
        abstract = True

class Blog(TimeStampedActivate):
    A blog belonging to a user.
    Blogs have multiple posts and one user can have many blogs.

    >>> b = Blog()
    >>> = 'Foo Blog'
    >>> b.user = User.objects.create(username='foo', password='test')
    >>> b.slug = 'foo-blog'
    >>> print b
    Foo Blog
    >>> print b.user.username
    name = models.CharField(max_length=255,
                            help_text="Name of your blog. 255 characters limit.")
    slug = models.SlugField()
    description = models.TextField(blank=True,
                                   help_text="Describe your blog.")
    user = models.ForeignKey(User, related_name="blogs")

    def __unicode__(self):

    def get_absolute_url(self):
        return ('blog', (), {
            'slug': self.slug

class Post(TimeStampedActivate):
    Post which belongs to a blog.

    >>> b = Blog.objects.get(id=1)
    >>> p = Post()
    >>> p.title = "A Test Post"
    >>> = b
    >>> p.body = "Just a small test"
    >>> p.slug = "a-test-post"
    >>> print
    Foo Blog
    >>> print
    title = models.CharField(max_length=255,
                             help_text="Title of the post.")
    slug = models.SlugField()
    excerpt = models.TextField(blank=True,
                               help_text="Small teaser. (Optional)")
    body = models.TextField(help_text="Markdown <a href=\"\">supported</a>")
    publish_at = models.DateTimeField(,
                                      help_text="Date and time post should become visible.")
    blog = models.ForeignKey(Blog, related_name="posts")
    tags = TaggableManager()
    objects = PostManager()

    def __unicode__(self):
        return self.title

    def is_visible(self):
        Checks posts for visibility.
        I.e: If scheduled to show next year, do not show this item.
        if and self.publish_at <=
            return True
        return False

    def get_absolute_url(self):
        return ('post', (), {
            'slug': self.slug

    class Meta:
        ordering = ['publish_at', '-modified', '-created']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.