Last active
August 29, 2015 14:06
-
-
Save ekalvi/b116dd73e5b0ca523ab0 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
from tastypie.utils.timezone import now | |
from django.contrib.auth.models import User | |
from django.db import models | |
from django.utils.text import slugify | |
class Entry(models.Model): | |
user = models.ForeignKey(User) | |
pub_date = models.DateTimeField(default=now) | |
title = models.CharField(max_length=200) | |
slug = models.SlugField() | |
body = models.TextField() | |
def __unicode__(self): | |
return self.title | |
def save(self, *args, **kwargs): | |
# For automatic slug generation. | |
if not self.slug: | |
self.slug = slugify(self.title)[:50] | |
return super(Entry, self).save(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment