Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = "ppb.apps.AppConfig" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,7 @@ | |
|
||
# external | ||
"pinax.blog", | ||
"taggit", | ||
|
||
# project | ||
"ppb", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pytz==2014.10 | |
psycopg2==2.6 | ||
|
||
requests==2.5.1 | ||
django-taggit==0.12.2 |