Ticket #15995: models.py

File models.py, 893 bytes (added by Florian Apolloner, 6 years ago)
Line 
1from django.contrib.auth.models import User
2from django.db import models
3
4
5class PostManager(models.Manager):
6    def get_query_set(self):
7        return super(PostManager, self).get_query_set().filter(public = True)
8
9
10class Post(models.Model):
11    author = models.ForeignKey(User, on_delete=models.PROTECT)
12
13    title = models.CharField(max_length=255)
14    slug = models.SlugField()
15
16    text = models.TextField()
17
18    pub_date = models.DateTimeField()
19    last_updated = models.DateTimeField()
20
21    public = models.BooleanField()
22
23    objects = models.Manager()
24    published = PostManager()
25
26    def __unicode__(self):
27        return self.title
28
29    @models.permalink
30    def get_absolute_url(self):
31        return ('blogy:detail', (), {
32            'year': self.pub_date.year,
33            'month': self.pub_date.month,
34            'day': self.pub_date.day,
35            'slug': self.slug})
Back to Top