PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 36ms app.codeStats 0ms

/example_app/models.py

https://bitbucket.org/neithere/django-view-shortcuts/
Python | 37 lines | 27 code | 9 blank | 1 comment | 0 complexity | 866ed1c9b859b9c0fd8410c331fa5477 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2
 3from django.core.urlresolvers import reverse
 4from django.db.models import CharField, ForeignKey, IntegerField, \
 5                             ManyToManyField, Model, TextField
 6from django.utils.translation import ugettext_lazy as _
 7
 8
 9class Author(Model):
10    name = CharField(max_length=255)
11    
12    __unicode__ = lambda s: s.name
13
14class Category(Model):
15    title = CharField(max_length=255)
16    
17    __unicode__ = lambda s: s.title
18
19
20class Story(Model):
21    DRAFT, PUBLISHED = 0, 1
22    STORY_STATUS_CHOICES = (
23        (DRAFT,     _('Draft')),
24        (PUBLISHED, _('Published')),
25    )
26    title    = CharField(max_length=255)
27    status   = IntegerField(_('Status'), choices=STORY_STATUS_CHOICES, default=DRAFT)
28    author   = ForeignKey(Author, related_name='stories', null=True,
29                          verbose_name=_('Written by'))
30    category = ManyToManyField(Category, null=True, #related_name='category_set',
31                               verbose_name=_('Category'))
32    text     = TextField()
33    
34    __unicode__ = lambda s: s.title
35    get_url     = lambda s: reverse('example-story-detail',
36                                    urlconf=None, args=None,
37                                    kwargs=dict(object_id=s.pk))