Mercurial > public > sg101
comparison gpp/forums/models.py @ 285:8fd4984d5c3b
This is a first rough commit for #95, adding the ability to embed YouTube videos in forum posts. Some more polish and testing needs to happen at this point. I wanted to get all these changes off my hard drive and into the repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 02:39:35 +0000 |
parents | d424b8bae71d |
children | c92fb89dbc7d |
comparison
equal
deleted
inserted
replaced
284:df2c81f705a8 | 285:8fd4984d5c3b |
---|---|
6 from django.db import models | 6 from django.db import models |
7 from django.db.models import Q | 7 from django.db.models import Q |
8 from django.contrib.auth.models import User, Group | 8 from django.contrib.auth.models import User, Group |
9 | 9 |
10 from core.markup import site_markup | 10 from core.markup import site_markup |
11 from oembed.models import Oembed | |
11 | 12 |
12 | 13 |
13 class Category(models.Model): | 14 class Category(models.Model): |
14 """ | 15 """ |
15 Forums belong to a category, whose access may be assigned to groups. | 16 Forums belong to a category, whose access may be assigned to groups. |
246 creation_date = models.DateTimeField(db_index=True) | 247 creation_date = models.DateTimeField(db_index=True) |
247 update_date = models.DateTimeField(db_index=True) | 248 update_date = models.DateTimeField(db_index=True) |
248 body = models.TextField() | 249 body = models.TextField() |
249 html = models.TextField() | 250 html = models.TextField() |
250 user_ip = models.IPAddressField(blank=True, default='', null=True) | 251 user_ip = models.IPAddressField(blank=True, default='', null=True) |
252 attachments = models.ManyToManyField(Oembed, through='Attachment') | |
251 | 253 |
252 class Meta: | 254 class Meta: |
253 ordering = ('creation_date', ) | 255 ordering = ('creation_date', ) |
254 get_latest_by = 'creation_date' | 256 get_latest_by = 'creation_date' |
255 verbose_name = 'forum post' | 257 verbose_name = 'forum post' |
363 super(TopicLastVisit, self).save(*args, **kwargs) | 365 super(TopicLastVisit, self).save(*args, **kwargs) |
364 | 366 |
365 def touch(self): | 367 def touch(self): |
366 self.last_visit = datetime.datetime.now() | 368 self.last_visit = datetime.datetime.now() |
367 | 369 |
370 | |
371 class Attachment(models.Model): | |
372 """ | |
373 This model is a "through" table for the M2M relationship between forum | |
374 posts and Oembed objects. | |
375 """ | |
376 post = models.ForeignKey(Post) | |
377 embed = models.ForeignKey(Oembed) | |
378 order = models.IntegerField() | |
379 | |
380 class Meta: | |
381 ordering = ('order', ) | |
382 | |
383 def __unicode__(self): | |
384 return u'Post %d, %s' % (self.post.pk, self.embed.title) |