Commits

Gregory Petukhov committed 9f0a08f

Refactoring. Add django-ckeditor

  • Participants
  • Parent commits 2d3b888

Comments (0)

Files changed (4)

 Dependencies
 ============
 
-*PIL
-*sorl-thumbnail
-*django-common
-*south
+* PIL
+* sorl-thumbnail
+* django-common
+* south
+* django-ckeditor
 
 
 Installation
 ============
 
-* Install django-article application and all its dependencies
+* Install django-article's dependencies
+* Install django-article application and configure them
 * Add article to INSTALLED_APPS
 * Put ARTICLE_PAGE_SIZE setting into settings.py
 * Do syncdb

File article/admin.py

 from article.models import Article, Category
 
 class ArticleAdmin(admin.ModelAdmin):
-    list_display = ['title', 'category', 'created', 'date_published', 'live_url',
-                    'image_thumbnail', 'is_starred']
+    list_display = ['title', 'category', 'created', 'live_url',
+                    'image_thumbnail']
     list_filter = ['category']
     search_fields = ['title', 'teaser', 'content']
     prepopulated_fields = {'slug': ['title']}

File article/models.py

 # -*- coding: utf-8 -*-
 from datetime import datetime
 from south.modelsinspector import add_introspection_rules
+from ckeditor.fields import RichTextField
 
 from django.db import models
 from django.core.urlresolvers import reverse
     title = models.CharField(max_length=255)
     slug = models.SlugField(max_length=255, blank=False, default=None)
     category = models.ForeignKey('article.Category', related_name='articles')
-    teaser = models.TextField()
-    content = models.TextField()
+    is_starred = models.BooleanField(blank=True, default=False)
+    teaser = RichTextField()
+    content = RichTextField()
     image = models.ImageField(blank=True,
             upload_to='upload/article/article_image')
     meta_keywords = models.CharField(max_length=255, blank=True)

File article/views.py

 from article.models import Article, Category
 
 def home_page(request):
-    context = {}
+    article_qs = Article.objects.order_by('-created')
+    page = paginate(article_qs, request)
+    context = {'page': page,
+            }
     return render(request, 'article/home_page.html', context)
 
 
 def category_details(request, category_slug):
     category = get_object_or_404(Category, slug=category_slug)
-    articles = Article.objects_published.filter(category=category)\
+    articles = Article.objects.filter(category=category)\
                       .order_by('-created')
     page = paginate(articles, request, settings.ARTICLE_PAGE_SIZE)
     context = {'page': page, 'category': category}
     return render(request, 'article/category_details.html', context)
 
 
-def article_details(request, pk, slug):
+def article_details(request, category_slug, pk, article_slug):
     article = get_object_or_404(Article, pk=pk)
     context = {'article': article}
     return render(request, 'article/article_details.html', context)