Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 30th, 2013  |  syntax: Python  |  size: 1.68 KB  |  hits: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Thread(models.Model):
  2.     class Meta:
  3.         get_latest_by = "post_date"
  4.    
  5.     author = models.ForeignKey(Player, related_name="threads")
  6.     post_date = models.DateTimeField()
  7.     parent = models.ForeignKey(Subsection, related_name="children")
  8.     close_note = models.ForeignKey(Note, null=True, blank=True)
  9.     sticky = models.BooleanField()
  10.     page_views = models.IntegerField(default=0)
  11.     def __str__(self):
  12.         return util.plaintext(self.title)
  13.     def to_url(self):
  14.         return str(self.id)
  15.     @property
  16.     def title(self):
  17.         try:
  18.             return self.children.order_by("post_date")[0].title
  19.         except IndexError:
  20.             return ""
  21. class Post(models.Model):
  22.     class Meta:
  23.         get_latest_by = "post_date"
  24.     title = models.CharField(max_length=max_title_length)
  25.     author = models.ForeignKey(Player, related_name="posts")
  26.     parent = models.ForeignKey(Thread, related_name="children")
  27.     post_date = models.DateTimeField()
  28.     last_edit_date = models.DateTimeField(blank=True, null=True)
  29.     text = models.TextField(max_length=max_post_length)
  30.     flag_note = models.ForeignKey(Note, blank=True, null=True)
  31.     objects = PostManager()
  32.     def __str__(self):
  33.         return util.plaintext(self.text)[:10]
  34.     def to_url(self):
  35.         return str(self.id)
  36.     @classmethod
  37.     def create(cls, title=None, text=None, author=None,
  38.                parent_id=None, post_date=None):
  39.         parent = Thread.objects.get(id=parent_id)
  40.         if post_date is None:
  41.             post_date = datetime.now()
  42.         return cls(title=title, author=author, parent=parent,
  43.                     post_date=post_date, text=text, flag_note=None)