Skip to content

Instantly share code, notes, and snippets.

@monokrome
Created August 15, 2011 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokrome/1147482 to your computer and use it in GitHub Desktop.
Save monokrome/1147482 to your computer and use it in GitHub Desktop.
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