data/managers.py
from django.db import models
class EntryManager(models.Manager):
def published_entries(self):
return self.model.objects.filter(published = True)
--------------------------------------------------------------------------------------------
data/models.py
#-*- coding: utf-8 -*-
from django.db import models
from blog.data.managers import EntryManager
class Entry(models.Model):
created = models.DateTimeField(auto_now_add = True)
updated = models.DateTimeField(auto_now = True)
title = models.CharField(max_length = 64)
text = models.TextField()
published = models.BooleanField(db_index = True, default = True)
objects = EntryManager()
def __unicode__(self):
return u'%s - %s' % (self.title, self.created)
--------------------------------------------------------------------------------------------
data/views.py
from django.shortcuts import render_to_response
from blog.data.models import Entry
def index(request):
entries = Entry.objects.published_entries().order_by('-id')
return render_to_response('homepage/index.html', {'entries': entries})
Комментариев нет:
Отправить комментарий