Created
August 15, 2011 19:10
-
-
Save monokrome/1147482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.gis.db import models | |
from django.contrib.auth.models import User | |
from django.conf import settings | |
auto_approve_comments = getattr(settings, 'COMMENTS_AUTO_APPROVE', True) | |
class Place(models.Model): | |
""" For maintaining a database of different places. """ | |
location = models.PointField() | |
name = models.CharField(max_length=128) | |
class CommentAttachment(models.Model): | |
""" A base class for attachment centralization. """ | |
pass | |
class ImageCommentAttachment(CommentAttachment): | |
""" An attachment which represents an image. """ | |
image = models.ImageField() # Using ImageKit here is more awesometastic. | |
class LocationAttachment(CommentAttachment): | |
""" A simple attachment which lets you attach a place to your post. """ | |
place = models.ForeignKey(Place) | |
class Comment(models.Model): | |
""" A comment. """ | |
text = models.TextField('Your comments') | |
author = models.ForeignKeyField(User) | |
published = models.BooleanField(default=auto_approve_comments) | |
attachments = models.ManyToManyField(CommentAttachment) | |
# This implies a parent->child relationship, which can be used to reprsent | |
# threaded replies in your comments. Consider using an MPTT application to | |
# help reduce queries. | |
reply_to = models.ForeignKey('self', null=True) | |
# relate to your products here, or - even better - use generic relations. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment