1 from django.db import models
2 from django.contrib.auth.models import User
3 from django.template.defaultfilters import slugify
4 import datetime
5
6 -class Tag(models.Model):
7 name = models.CharField(max_length=50)
8 slug = models.SlugField(editable=False)
9
12
13 - def save(self, *args, **kwargs):
17
18 -class Entry(models.Model):
19 title = models.CharField(max_length=200)
20 slug = models.SlugField(editable=False)
21 summary = models.CharField(max_length=200,blank=True,null=True,help_text="One sentence. If not supplied, whole body text will show up in archive view.")
22 body = models.TextField(help_text="Use HTML.")
23 tags = models.ManyToManyField(Tag)
24 author = models.ForeignKey(User)
25 is_draft = models.BooleanField("Draft", default=False, help_text="Check if this is a draft.")
26 published_on = models.DateTimeField(auto_now_add=True)
27 modified_on = models.DateTimeField(auto_now=True,editable=False)
28
33
34 - def __unicode__(self):
36
37 - def save(self, *args, **kwargs):
38 if not self.id:
39 self.slug = slugify(self.title)
40 super(Entry, self).save(*args, **kwargs)
41