Mercurial > public > sg101
comparison gpp/comments/models.py @ 14:7b6540b185d9
Added get_absolute_url() for my comments. Had to add a get_absolute_url() function for downloads in the process.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 18 Apr 2009 19:14:17 +0000 |
parents | dbd703f7d63a |
children | d0d779dd0832 |
comparison
equal
deleted
inserted
replaced
13:777451a98f9d | 14:7b6540b185d9 |
---|---|
5 from django.conf import settings | 5 from django.conf import settings |
6 from django.contrib.contenttypes.models import ContentType | 6 from django.contrib.contenttypes.models import ContentType |
7 from django.contrib.contenttypes import generic | 7 from django.contrib.contenttypes import generic |
8 from django.contrib.auth.models import User | 8 from django.contrib.auth.models import User |
9 from django.template.loader import render_to_string | 9 from django.template.loader import render_to_string |
10 from django.core import urlresolvers | |
10 | 11 |
11 | 12 |
12 COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000) | 13 COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000) |
13 | 14 |
14 class CommentManager(models.Manager): | 15 class CommentManager(models.Manager): |
41 '"This comment has been removed" message') | 42 '"This comment has been removed" message') |
42 | 43 |
43 # Attach manager | 44 # Attach manager |
44 objects = CommentManager() | 45 objects = CommentManager() |
45 | 46 |
47 class Meta: | |
48 ordering = ('creation_date', ) | |
49 | |
46 def __unicode__(self): | 50 def __unicode__(self): |
47 return u'%s: %s...' % (self.user.username, self.comment[:50]) | 51 return u'%s: %s...' % (self.user.username, self.comment[:50]) |
48 | |
49 class Meta: | |
50 ordering = ('creation_date', ) | |
51 | 52 |
52 def save(self, force_insert=False, force_update=False): | 53 def save(self, force_insert=False, force_update=False): |
53 html = render_to_string('comments/markdown.html', {'data': self.comment}) | 54 html = render_to_string('comments/markdown.html', {'data': self.comment}) |
54 self.html = html.strip() | 55 self.html = html.strip() |
55 super(Comment, self).save(force_insert, force_update) | 56 super(Comment, self).save(force_insert, force_update) |
57 | |
58 def get_absolute_url(self): | |
59 return self.get_content_object_url() + ('#c%s' % self.id) | |
60 | |
61 def get_content_object_url(self): | |
62 """ | |
63 Get a URL suitable for redirecting to the content object. | |
64 """ | |
65 return urlresolvers.reverse( | |
66 "comments-url-redirect", | |
67 args=(self.content_type_id, self.object_id) | |
68 ) | |
56 | 69 |
57 | 70 |
58 class CommentFlag(models.Model): | 71 class CommentFlag(models.Model): |
59 """This model represents a user flagging a comment as inappropriate.""" | 72 """This model represents a user flagging a comment as inappropriate.""" |
60 user = models.ForeignKey(User) | 73 user = models.ForeignKey(User) |