Source

djangoschool / djangoschool / apps / core / models.py

Full commit
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

from markitup.fields import MarkupField


class Blog(models.Model):
    title = models.CharField(_('title'), max_length=200)
    desc = models.TextField(_('description'))
    user = models.ForeignKey(User, verbose_name=_('user'))
    
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    
    class Meta:
        verbose_name = _('blog')
        verbose_name_plural = _('blogs')
        
    def __unicode__(self):
        return self.title


class Entry(models.Model):
    title = models.CharField(_('title'), max_length=200)
    content = MarkupField(_('content'))
    content_short = models.TextField(_('short content'), null=True,
            blank=True)
    user = models.ForeignKey(User, verbose_name=_('user'))
    blog = models.ForeignKey(Blog, verbose_name=_('blog'))
    
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = _('entry')
        verbose_name_plural = _('entries')

    def __unicode__(self):
        return self.title

    @models.permalink
    def get_absolute_url(self):
        return ('core_entry_detail', (), {'entry_id': self.pk})


class Comment(models.Model):
    content = models.TextField(_('content'))
    created = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(User, verbose_name=_('user'))
    entry = models.ForeignKey(Entry, verbose_name=_('entry'))

    class Meta:
        verbose_name = _('comment')
        verbose_name_plural = _('comments')
        ordering = ['created']

    def __unicode__(self):
        return '%s: %s' % (self.user.username, self.entry.title)