Skip to content

Instantly share code, notes, and snippets.

@erikhazzard
Created December 16, 2010 04:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erikhazzard/743027 to your computer and use it in GitHub Desktop.
Save erikhazzard/743027 to your computer and use it in GitHub Desktop.
#----------------------------------------
#Post
#----------------------------------------
class Post(models.Model):
#Slug is the 'short' version of the title, used in the URL and
# used as the primary key
slug = models.CharField(
primary_key=True,
max_length=255
)
#title of blog post
title = models.CharField(
max_length=255
)
#Save the post date
post_date = models.DateTimeField()
#If the post has been edited
post_last_edit_date = models.DateTimeField(
blank=True,
null=True
)
#num_views will store the times the page has been accessed
num_views = models.IntegerField(
blank=True,
null=True
)
#optional image
related_image = models.ImageField(
'Associated Image',
blank=True,
null=True,
upload_to='blog_images'
)
#category the post belongs to
category = models.ForeignKey(Category)
#tags this post contains
tags = models.ManyToManyField(
Tag,
null=True,
blank=True)
#content is the actual contents of the post
content = models.TextField()
#Short description of the post
description = models.TextField()
#------------------------------------
#Post functions
#------------------------------------
def get_url(self):
#Return the URL as category/post
return 'http://vasir.net/blog/%s/%s/' % (
self.category.slug,
self.slug)
def __unicode__(self):
return '%s (%s)' % (self.title, self.slug)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment