Fixup for blog.Post

A little automation for first time saving: set created_at and slug fields
This commit is contained in:
Gergely Polonkai 2013-10-02 13:24:04 +02:00
parent a662ee063b
commit 2eecd9caa8

View File

@ -4,12 +4,18 @@ from taggit.managers import TaggableManager
class Post(models.Model): class Post(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
created_at = models.DateTimeField() created_at = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length = 100) title = models.CharField(max_length = 100)
slug = models.CharField(max_length = 100) slug = models.SlugField(editable=False, max_length = 100)
content = models.TextField() content = models.TextField()
draft = models.BooleanField() draft = models.BooleanField()
tags = TaggableManager() tags = TaggableManager()
def __unicode__(self): def __unicode__(self):
return self.title return self.title
def save(self, *args, **kwargs):
if not self.id:
self.slug = slugify(self.title)
super(Post, self).save(*args, **kwargs)