evorepo/news/models.py
Dan McGee 97d1e4164b Connect post_save signals where they will always be triggered
We need to do this in the models.py files, otherwise the post_save signal
might not be connected right away on launch of the application. Move them
over there, add a dispatch_uid so it only gets hooked up once, and do some
other function moving around so we don't have circular imports.

Signed-off-by: Dan McGee <dan@archlinux.org>
2010-10-13 18:11:28 -05:00

33 lines
1.0 KiB
Python

from django.db import models
from django.contrib.auth.models import User
class News(models.Model):
id = models.AutoField(primary_key=True)
slug = models.SlugField(max_length=255, unique=True)
author = models.ForeignKey(User, related_name='news_author')
postdate = models.DateTimeField("post date", auto_now_add=True, db_index=True)
last_modified = models.DateTimeField(editable=False,
auto_now=True, db_index=True)
title = models.CharField(max_length=255)
content = models.TextField()
def get_absolute_url(self):
return '/news/%s/' % self.slug
def __unicode__(self):
return self.title
class Meta:
db_table = 'news'
verbose_name_plural = 'news'
get_latest_by = 'postdate'
ordering = ['-postdate']
# connect signals needed to keep cache in line with reality
from main.utils import refresh_news_latest
from django.db.models.signals import post_save
post_save.connect(refresh_news_latest, sender=News,
dispatch_uid="news.models")
# vim: set ts=4 sw=4 et: