comparison gpp/comments/models.py @ 294:254db4cb6a86

Changes / scripts to import forums. Other tweaks and moving other import scripts to the legacy application.
author Brian Neal <bgneal@gmail.com>
date Wed, 05 Jan 2011 04:09:35 +0000
parents 5c889b587416
children 24f1230f3ee3
comparison
equal deleted inserted replaced
293:c92fb89dbc7d 294:254db4cb6a86
1 """ 1 """
2 Models for the comments application. 2 Models for the comments application.
3 """ 3 """
4 import datetime
5
4 from django.db import models 6 from django.db import models
5 from django.conf import settings 7 from django.conf import settings
6 from django.contrib.contenttypes.models import ContentType 8 from django.contrib.contenttypes.models import ContentType
7 from django.contrib.contenttypes import generic 9 from django.contrib.contenttypes import generic
8 from django.contrib.auth.models import User 10 from django.contrib.auth.models import User
32 object_id = models.PositiveIntegerField() 34 object_id = models.PositiveIntegerField()
33 content_object = generic.GenericForeignKey('content_type', 'object_id') 35 content_object = generic.GenericForeignKey('content_type', 'object_id')
34 user = models.ForeignKey(User) 36 user = models.ForeignKey(User)
35 comment = models.TextField(max_length=COMMENT_MAX_LENGTH) 37 comment = models.TextField(max_length=COMMENT_MAX_LENGTH)
36 html = models.TextField(blank=True) 38 html = models.TextField(blank=True)
37 creation_date = models.DateTimeField(auto_now_add=True) 39 creation_date = models.DateTimeField()
38 ip_address = models.IPAddressField('IP Address') 40 ip_address = models.IPAddressField('IP Address')
39 is_public = models.BooleanField(default=True, 41 is_public = models.BooleanField(default=True,
40 help_text='Uncheck this field to make the comment invisible.') 42 help_text='Uncheck this field to make the comment invisible.')
41 is_removed = models.BooleanField(default=False, 43 is_removed = models.BooleanField(default=False,
42 help_text='Check this field to replace the comment with a ' \ 44 help_text='Check this field to replace the comment with a ' \
43 '"This comment has been removed" message') 45 '"This comment has been removed" message')
44 46
50 52
51 def __unicode__(self): 53 def __unicode__(self):
52 return u'%s: %s...' % (self.user.username, self.comment[:50]) 54 return u'%s: %s...' % (self.user.username, self.comment[:50])
53 55
54 def save(self, *args, **kwargs): 56 def save(self, *args, **kwargs):
57 if not self.id:
58 self.creation_date = datetime.datetime.now()
59
55 self.html = site_markup(self.comment) 60 self.html = site_markup(self.comment)
56 super(Comment, self).save(*args, **kwargs) 61 super(Comment, self).save(*args, **kwargs)
57 62
58 def get_absolute_url(self): 63 def get_absolute_url(self):
59 return self.get_content_object_url() + ('#c%s' % self.id) 64 return self.get_content_object_url() + ('#c%s' % self.id)