Commit 39291c87 authored by fred's avatar fred

episode: add tags, using the taggit application

parent ca109519
...@@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse ...@@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse
from django.db import models from django.db import models
from ckeditor.fields import RichTextField from ckeditor.fields import RichTextField
from taggit.managers import TaggableManager
class Category(models.Model): class Category(models.Model):
...@@ -69,6 +70,7 @@ class Episode(models.Model): ...@@ -69,6 +70,7 @@ class Episode(models.Model):
slug = models.SlugField() slug = models.SlugField()
description = RichTextField(null=True, blank=True) description = RichTextField(null=True, blank=True)
text = RichTextField(null=True) text = RichTextField(null=True)
tags = TaggableManager(blank=True)
# XXX: languages (models.ManyToManyField(Language)) # XXX: languages (models.ManyToManyField(Language))
......
...@@ -15,7 +15,10 @@ class EmissionIndex(indexes.SearchIndex, indexes.Indexable): ...@@ -15,7 +15,10 @@ class EmissionIndex(indexes.SearchIndex, indexes.Indexable):
class EpisodeIndex(indexes.SearchIndex, indexes.Indexable): class EpisodeIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True) text = indexes.CharField(document=True, use_template=True)
tags = indexes.MultiValueField(faceted=True)
def get_model(self): def get_model(self):
return Episode return Episode
def prepare_tags(self, obj):
return [tag.name for tag in obj.tags.all()]
...@@ -3,3 +3,5 @@ ...@@ -3,3 +3,5 @@
{{ object.description|striptags }} {{ object.description|striptags }}
{{ object.text|striptags }} {{ object.text|striptags }}
{% for tag in object.tags.all %} {{ tag.name }} {% endfor %}
...@@ -125,6 +125,7 @@ INSTALLED_APPS = ( ...@@ -125,6 +125,7 @@ INSTALLED_APPS = (
'south', 'south',
'ckeditor', 'ckeditor',
'haystack', 'haystack',
'taggit',
'panikdb.emissions', 'panikdb.emissions',
) )
...@@ -171,7 +172,7 @@ CKEDITOR_CONFIGS = { ...@@ -171,7 +172,7 @@ CKEDITOR_CONFIGS = {
HAYSTACK_CONNECTIONS = { HAYSTACK_CONNECTIONS = {
'default': { 'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8080/solr' 'URL': 'http://127.0.0.1:8983/solr/panik'
}, },
} }
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
<!-- Begin faceting. --> <!-- Begin faceting. -->
<p> <p>
{% if facets.fields.categories %} {% if facets.fields.categories %}
{# Provide only the top 5 authors #} Catégories :
{# Provide only the top 5 categories #}
{% for category in facets.fields.categories|slice:":5" %} {% for category in facets.fields.categories|slice:":5" %}
<span><a href="{{ request.get_full_path }}&amp;selected_facets=categories_exact:{{ category.0|urlencode }}">{{ category.0 }}</a> ({{ category.1 }})</span> <span><a href="{{ request.get_full_path }}&amp;selected_facets=categories_exact:{{ category.0|urlencode }}">{{ category.0 }}</a> ({{ category.1 }})</span>
{% endfor %} {% endfor %}
...@@ -27,6 +28,19 @@ ...@@ -27,6 +28,19 @@
{% endif %} {% endif %}
</p> </p>
<p>
{% if facets.fields.tags %}
Tags :
{# Provide only the top 5 tags #}
{% for tag in facets.fields.tags|slice:":5" %}
<span><a href="{{ request.get_full_path }}&amp;selected_facets=tags_exact:{{ tag.0|urlencode }}">{{ tag.0 }}</a> ({{ tag.1 }})</span>
{% endfor %}
{% else %}
No tags facets.
{% endif %}
</p>
<!-- End faceting --> <!-- End faceting -->
<h3>Résultats</h3> <h3>Résultats</h3>
......
...@@ -10,7 +10,7 @@ from haystack.views import FacetedSearchView, search_view_factory ...@@ -10,7 +10,7 @@ from haystack.views import FacetedSearchView, search_view_factory
from haystack.forms import FacetedSearchForm from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet from haystack.query import SearchQuerySet
sqs = SearchQuerySet().facet('categories') sqs = SearchQuerySet().facet('categories').facet('tags')
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^$', RedirectView.as_view(url=reverse_lazy('emission-list'))), url(r'^$', RedirectView.as_view(url=reverse_lazy('emission-list'))),
......
Django<1.6 Django<1.6
south>=0.8,<0.9 south>=0.8,<0.9
django-ckeditor django-ckeditor
django-taggit
git+https://github.com/toastdriven/django-haystack.git git+https://github.com/toastdriven/django-haystack.git
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment