class Post models Model slug models SlugField max_length 255 core True

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Post(models.Model):
slug = models.SlugField(max_length=255, core=True, prepopulate_from=('title',))
title = models.CharField(max_length=255)
meta_title = models.CharField(max_length=255, blank=True, null=True)
text = models.TextField()
html = models.TextField(editable=False, blank=True)
render_method = models.CharField(choices=settings.RENDER_METHODS, max_length=16)
category = models.ForeignKey(Category)
pub_date = models.DateTimeField('date', auto_now_add=True)
author = models.ForeignKey(User)
meta_keywords = models.TextField()
meta_description = models.TextField()
images = generic.GenericRelation(Storage)
def save(self):
self.text = self.text.strip()
self.html = render(self.text, self.render_method)
if not self.id:
self.category.posts_count = self.category.post_set.count() + 1
self.category.save()
super(Post, self).save()
try:
ping_google()
except Exception:
pass
def delete(self):
self.category.posts_count = self.category.post_set.count() - 1
self.category.save()
super(Post, self).delete()
def __unicode__(self):
return smart_unicode(self.title)
@permalink
def get_absolute_url(self):
return ('blog.views.post_view', [str(self.category.slug), str(self.slug)])
class Meta:
verbose_name = 'blog post'
verbose_name_plural = 'blog posts'
get_latest_by = ('pub_date')
ordering = ['-pub_date']
class Admin:
list_display = ('title', 'slug', 'category')
list_filter = ('category',)
date_hierarchy = 'pub_date'
fields = (
('Title',
{'fields':
('title', 'slug')}),
('Content',
{'fields': ('author', 'text', 'render_method', 'category')}),
('Meta Information',
{'fields':
('meta_title', 'meta_keywords', 'meta_description')}),
)