annotate gpp/mailer/models.py @ 318:c550933ff5b6

Fix a bug where you'd get an error when trying to delete a forum thread (topic does not exist). Apparently when you call topic.delete() the posts would get deleted, but the signal handler for each one would run, and it would try to update the topic's post count or something, but the topic was gone? Reworked the code a bit and explicitly delete the posts first. I also added a sync() call on the parent forum since post counts were not getting adjusted.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 Feb 2011 21:46:52 +0000
parents aef00df91165
children
rev   line source
bgneal@180 1 """Models for the mailer application."""
bgneal@180 2 import datetime
bgneal@180 3
bgneal@180 4 from django.db import models
bgneal@180 5
bgneal@180 6
bgneal@180 7 MAX_SUBJECT = 120
bgneal@180 8
bgneal@180 9 class Message(models.Model):
bgneal@180 10 """The model to represent stored emails in the database."""
bgneal@180 11 from_address = models.EmailField()
bgneal@180 12 to_address = models.EmailField()
bgneal@180 13 subject = models.CharField(max_length=MAX_SUBJECT)
bgneal@180 14 body = models.TextField()
bgneal@180 15 creation_date = models.DateTimeField()
bgneal@180 16
bgneal@180 17 class Meta:
bgneal@180 18 ordering = ('creation_date', )
bgneal@180 19
bgneal@180 20 def __unicode__(self):
bgneal@180 21 return u'From: %s, To: %s, Subj: %s' % (
bgneal@180 22 self.from_address, self.to_address, self.subject)
bgneal@180 23
bgneal@180 24 def save(self, *args, **kwargs):
bgneal@180 25 if self.id is None:
bgneal@180 26 self.creation_date = datetime.datetime.now()
bgneal@180 27 super(Message, self).save(*args, **kwargs)