legacy-dotfiles/blog/models.py

34 lines
1 KiB
Python
Raw Normal View History

2011-10-17 01:34:04 +02:00
from django.db import models
from main.models import Tag, Activity
from django.db.models.signals import post_save, post_delete
class Post(models.Model):
subject = models.CharField(max_length=500)
body = models.TextField()
tags = models.ManyToManyField(Tag, null=True, blank=True)
postdate = models.DateTimeField(auto_now=True)
def __unicode__(self):
return self.subject
def post_saved_callback(sender, **kwargs):
if kwargs['created']:
acttype = 'add'
else:
acttype = 'edit'
a = Activity(actcategory='blog',
actdescription=kwargs["instance"].subject,
acttype = acttype,
objpk = kwargs["instance"].pk)
a.save()
def post_deleted_callback(sender, **kwargs):
a = Activity(actcategory='blog',
actdescription=kwargs["instance"].subject,
acttype = 'delete')
a.save()
post_save.connect(post_saved_callback, sender=Post)
post_delete.connect(post_deleted_callback, sender=Post)