sphinx_django/sphinxcomment/models.py~
changeset 2 f5e18f8ed036
parent 0 54f784230511
equal deleted inserted replaced
1:5574cfc2b28d 2:f5e18f8ed036
     1 from django.db import models
     1 from django.db import models
     2 
     2 
     3 # Create your models here.
     3 # Create your models here.
     4 from django.db import models
     4 from django.db import models
     5 import sha
     5 
     6 
     6 
     7 mutable = True
     7 mutable = True
     8 
     8 
     9 class Chapter(models.Model):
     9 class Element(models.Model):
    10     id = models.CharField('ID attribute', max_length=64, editable=False,
    10     paragraph_id = models.CharField('Paragraph Id', max_length=100, editable=False, primary_key=True) 
    11                           primary_key=True)
    11     chapter_name = models.CharField('Chapter name', max_length=100, editable=False,db_index=True)
    12     chapter = models.CharField('Chapter ID', max_length=100, editable=False,
    12     
    13                                db_index=True)
       
    14 
       
    15 
    13 
    16     def __unicode__(self):
    14     def __unicode__(self):
    17         return self.id
    15         return self.paragraph_id
    18     
    16     
    19 class Comment(models.Model):
    17 class Comment(models.Model):
    20     element = models.ForeignKey(Element,
    18     element = models.ForeignKey(Element,
    21         help_text='ID of paragraph that was commented on')
    19         help_text='ID of paragraph that was commented on')
    22     comment = models.TextField(editable=mutable,
    20     comment = models.TextField(editable=mutable,
    27         help_text='Self-reported URL of submitter (may be empty or bogus)')
    25         help_text='Self-reported URL of submitter (may be empty or bogus)')
    28     ip = models.IPAddressField('IP address', editable=mutable,
    26     ip = models.IPAddressField('IP address', editable=mutable,
    29         help_text='IP address from which comment was submitted')
    27         help_text='IP address from which comment was submitted')
    30     date = models.DateTimeField('date submitted', auto_now=True,
    28     date = models.DateTimeField('date submitted', auto_now=True,
    31                                 auto_now_add=True)
    29                                 auto_now_add=True)
    32     reviewed = models.BooleanField(default=False, db_index=True,
       
    33         help_text='Has this comment been reviewed by an author?')
       
    34     hidden = models.BooleanField(default=False, db_index=True,
       
    35         help_text='Has this comment been hidden from public display?')
       
    36 
    30 
    37     def __unicode__(self):
    31     def __unicode__(self):
    38         return self.comment[:32]
    32         return self.comment[:32]
    39 
    33 
    40     def get_absolute_url(self):
    34     
    41         s = sha.new()
       
    42         s.update(repr(self.comment))
       
    43         s.update(repr(self.submitter_name))
       
    44         s.update(str(self.date))
       
    45         return '/read/%s.html#%s?comment=%s&uuid=%s' % (
       
    46             self.element.chapter, self.element.id, self.id, s.hexdigest()[:20]
       
    47             )