Permalink
Browse files

Add tagging support

  • Loading branch information...
paltman committed Feb 17, 2015
1 parent 09d48d1 commit 4cd35fa31d031a7b521aa7cf14ad7b4fa76153f9
Showing with 90 additions and 0 deletions.
  1. +1 −0 ppb/__init__.py
  2. +66 −0 ppb/admin.py
  3. +4 −0 ppb/apps.py
  4. +16 −0 ppb/forms.py
  5. +1 −0 ppb/management/commands/make_release_notes.py
  6. 0 ppb/receivers.py
  7. +1 −0 ppb/settings.py
  8. +1 −0 requirements.txt
View
@@ -0,0 +1 @@
default_app_config = "ppb.apps.AppConfig"
View
@@ -0,0 +1,66 @@
from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from pinax.blog.admin import PostAdmin
from pinax.blog.models import Post
from taggit.models import TaggedItem
from .forms import AdminPostTagsForm
class TaggitListFilter(SimpleListFilter):
"""
A custom filter class that can be used to filter by taggit tags in the admin.
From: https://djangosnippets.org/snippets/2807/
"""
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = "tags"
# Parameter for the filter that will be used in the URL query.
parameter_name = "tag"
def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each tuple is the coded value
for the option that will appear in the URL query. The second element is the
human-readable name for the option that will appear in the right sidebar.
"""
tag_list = []
tags = TaggedItem.tags_for(model_admin.model)
for tag in tags:
tag_list.append((tag.name, tag.name))
return tag_list
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value provided in the query
string and retrievable via `self.value()`.
"""
if self.value():
return queryset.filter(tags__name__in=[self.value()])
class PostTagsAdmin(PostAdmin):
form = AdminPostTagsForm
fields = [
"section",
"title",
"slug",
"author",
"markup",
"teaser",
"content",
"description",
"primary_image",
"sharable_url",
"publish",
"tags"
]
list_filter = ["section", TaggitListFilter]
admin.site.unregister(Post)
admin.site.register(Post, PostTagsAdmin)
View
@@ -1,10 +1,14 @@
from django.apps import AppConfig as BaseAppConfig
from django.utils.importlib import import_module
from pinax.blog.models import Post
from taggit.managers import TaggableManager
class AppConfig(BaseAppConfig):
name = "ppb"
def ready(self):
Post.add_to_class("tags", TaggableManager())
import_module("ppb.receivers")
View
@@ -0,0 +1,16 @@
from pinax.blog.forms import FIELDS, AdminPostForm
from pinax.blog.models import Post
from taggit.forms import TagField
FIELDS.append("tags")
class AdminPostTagsForm(AdminPostForm):
tags = TagField()
class Meta:
model = Post
fields = FIELDS
@@ -144,6 +144,7 @@ def create_post(self, name, release_url, version, date, commits):
updated=date,
published=date
)
post.tags.add(name)
Revision.objects.create(
post=post,
title=post.title,
View
No changes.
View
@@ -127,6 +127,7 @@
# external
"pinax.blog",
"taggit",
# project
"ppb",
View
@@ -5,3 +5,4 @@ pytz==2014.10
psycopg2==2.6
requests==2.5.1
django-taggit==0.12.2

0 comments on commit 4cd35fa

Please sign in to comment.