bgneal@180: """Models for the mailer application.""" bgneal@180: import datetime bgneal@180: bgneal@180: from django.db import models bgneal@180: bgneal@180: bgneal@180: MAX_SUBJECT = 120 bgneal@180: bgneal@180: class Message(models.Model): bgneal@180: """The model to represent stored emails in the database.""" bgneal@180: from_address = models.EmailField() bgneal@180: to_address = models.EmailField() bgneal@180: subject = models.CharField(max_length=MAX_SUBJECT) bgneal@180: body = models.TextField() bgneal@180: creation_date = models.DateTimeField() bgneal@180: bgneal@180: class Meta: bgneal@180: ordering = ('creation_date', ) bgneal@180: bgneal@180: def __unicode__(self): bgneal@180: return u'From: %s, To: %s, Subj: %s' % ( bgneal@180: self.from_address, self.to_address, self.subject) bgneal@180: bgneal@180: def save(self, *args, **kwargs): bgneal@180: if self.id is None: bgneal@180: self.creation_date = datetime.datetime.now() bgneal@180: super(Message, self).save(*args, **kwargs)