2013-09-24 13:54:41 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
2013-10-02 19:49:55 +00:00
|
|
|
from django.template.defaultfilters import slugify
|
2013-10-01 19:18:11 +00:00
|
|
|
from taggit.managers import TaggableManager
|
2013-09-24 13:54:41 +00:00
|
|
|
|
|
|
|
class Post(models.Model):
|
|
|
|
user = models.ForeignKey(User)
|
2014-04-21 08:39:43 +00:00
|
|
|
created_at = models.DateTimeField(auto_now_add = True)
|
2013-09-24 13:54:41 +00:00
|
|
|
title = models.CharField(max_length = 100)
|
2014-04-21 08:39:43 +00:00
|
|
|
slug = models.SlugField(editable = False, max_length = 100)
|
2013-09-24 13:54:41 +00:00
|
|
|
content = models.TextField()
|
|
|
|
draft = models.BooleanField()
|
2013-10-01 19:18:11 +00:00
|
|
|
tags = TaggableManager()
|
2013-09-24 13:54:41 +00:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
2013-10-02 11:24:04 +00:00
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if not self.id:
|
|
|
|
self.slug = slugify(self.title)
|
|
|
|
|
|
|
|
super(Post, self).save(*args, **kwargs)
|
2013-10-02 19:49:55 +00:00
|
|
|
|
2014-06-21 20:06:42 +00:00
|
|
|
def created_at_rss(self):
|
|
|
|
return self.created_at.strftime('%a, %d %b %Y %T %z')
|
|
|
|
|
2013-10-02 19:49:55 +00:00
|
|
|
class CodeChunk(models.Model):
|
|
|
|
language = models.CharField(max_length = 20)
|
2014-04-21 08:39:43 +00:00
|
|
|
created_at = models.DateTimeField(auto_now_add = True)
|
2013-10-02 19:49:55 +00:00
|
|
|
title = models.CharField(max_length = 100)
|
|
|
|
slug = models.SlugField(editable = False, max_length = 100)
|
2014-04-21 08:39:43 +00:00
|
|
|
description = models.TextField(blank = True)
|
2013-10-02 19:49:55 +00:00
|
|
|
content = models.TextField()
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if not self.id:
|
|
|
|
self.slug = slugify(self.title)
|
|
|
|
|
|
|
|
super(CodeChunk, self).save(*args, **kwargs)
|
|
|
|
|