annotate gpp/shoutbox/models.py @ 22:42f22c56ab05

Downloads: provide a count of search results on the search results template.
author Brian Neal <bgneal@gmail.com>
date Sun, 19 Apr 2009 21:01:15 +0000
parents 777451a98f9d
children e1d1a70d312d
rev   line source
gremmie@1 1 """
gremmie@1 2 Models for the shoutbox application.
gremmie@1 3 """
gremmie@1 4 from django.db import models
gremmie@1 5 from django.contrib.auth.models import User
gremmie@1 6
bgneal@13 7
gremmie@1 8 class Shout(models.Model):
bgneal@13 9 user = models.ForeignKey(User)
bgneal@13 10 shout_date = models.DateTimeField(auto_now_add=True)
bgneal@13 11 shout = models.TextField()
gremmie@1 12
bgneal@13 13 @models.permalink
bgneal@13 14 def get_absolute_url(self):
bgneal@13 15 return ('shoutbox-view', [str(self.id)])
gremmie@1 16
bgneal@13 17 def __unicode__(self):
bgneal@13 18 shout = self.shout[:60]
bgneal@13 19 return u'Shout from %s: %s' % (self.user.username, shout)
bgneal@13 20
bgneal@13 21 class Meta:
bgneal@13 22 ordering = ('-shout_date', )
bgneal@13 23
bgneal@13 24
bgneal@13 25 class ShoutFlag(models.Model):
bgneal@13 26 """This model represents a user flagging a shout as inappropriate."""
bgneal@13 27 user = models.ForeignKey(User)
bgneal@13 28 shout = models.ForeignKey(Shout)
bgneal@13 29 flag_date = models.DateTimeField(auto_now_add=True)
bgneal@13 30
bgneal@13 31 def __unicode__(self):
bgneal@13 32 return u'Shout ID %s flagged by %s' % (self.shout_id, self.user.username)
bgneal@13 33
bgneal@13 34 class Meta:
bgneal@13 35 ordering = ('flag_date', )
bgneal@13 36
bgneal@13 37 def get_shout_url(self):
bgneal@13 38 return '<a href="/admin/shoutbox/shout/%s">Shout</a>' % self.shout.id
bgneal@13 39 get_shout_url.allow_tags = True
bgneal@13 40
bgneal@13 41 # vim: ts=4 sw=4