hgbook-ja / web / hgbook / comments / models.py

from django.db import models
import sha

mutable = True

class Element(models.Model):
    id = models.CharField('ID attribute', max_length=64, editable=False,
    chapter = models.CharField('Chapter ID', max_length=100, editable=False,
    title = models.CharField('Section title', max_length=256, editable=False)

    def __unicode__(self):
        return self.id
class Comment(models.Model):
    element = models.ForeignKey(Element,
        help_text='ID of paragraph that was commented on')
    comment = models.TextField(editable=mutable,
        help_text='Text of submitted comment (please do not modify)')
    submitter_name = models.CharField('Submitter', max_length=64,
        help_text='Self-reported name of submitter (may be bogus)')
    submitter_url = models.URLField('URL', blank=True, editable=mutable,
        help_text='Self-reported URL of submitter (may be empty or bogus)')
    ip = models.IPAddressField('IP address', editable=mutable,
        help_text='IP address from which comment was submitted')
    date = models.DateTimeField('date submitted', auto_now=True,
    reviewed = models.BooleanField(default=False, db_index=True,
        help_text='Has this comment been reviewed by an author?')
    hidden = models.BooleanField(default=False, db_index=True,
        help_text='Has this comment been hidden from public display?')

    def __unicode__(self):
        return self.comment[:32]

    def get_absolute_url(self):
        s = sha.new()
        return '/read/%s.html#%s?comment=%s&uuid=%s' % (
            self.element.chapter, self.element.id, self.id, s.hexdigest()[:20]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.