Created
December 16, 2010 04:26
-
-
Save erikhazzard/743027 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
#---------------------------------------- | |
#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