Question

I am trying to figure out what I thought would be easy to find an answer for. I am using django-taggit in a project and I simply want to return a list of objects when a tag is selected. I have tried this:

How do I create list and detail views for django-taggit?

But I cannot get it to work. It just renders a blank page. I think the problem is in my template code. Maybe someone can point me in the direction. Any help would be appreciated..Thanks a lot.

Here is my code:

models.py

from taggit.managers import TaggableManager
from django.template.defaultfilters import slugify
from ckeditor.fields import RichTextField 
from taggit.models import TaggedItemBase

class Tagged(TaggedItemBase):
content_object = models.ForeignKey('Shows')

class Shows(models.Model):

title = models.CharField(max_length=40)
slug = models.SlugField(null=True, blank=True, unique=True)
tags = TaggableManager(through=Tagged)
hosts = models.ManyToManyField('Host', blank=True, null=True)
featured = models.BooleanField(default=False)
thumbnail = FilerImageField(related_name="thumbnail", help_text="Image should be: 550 X 350.")
playing_next = models.DateTimeField(null=True, blank=True)
description = RichTextField()

views.py:

class TaggedList(ListView):
queryset = Shows.objects.all()
paginate_by = 10
template_name = "tagged.html"

def get_queryset(self):
    return Shows.objects.filter(tags__name__in=[self.kwargs['tag']])

urls.py:

urlpatterns = patterns('radio.views',
                   url(r'^$', 'main', name='app_main'),
                   url(r'^(?P<slug>[^\.]+)/detail/$', 'detail_view', name='detailsview'),
                   url(r'^(?P<tag>\w+)/$', TaggedList.as_view()),
                   url(r'^tagged/(?P<tag>\w+)/$', TaggedList.as_view())

                   )
Was it helpful?

Solution 2

did you iterate over object_list in template? Because default list name in LiseView is object_list: doc: https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#listview

OTHER TIPS

Template code:

{% for objects in object_list %}
    {{ objects.title }}
    {{ objects.tag }}
    {{ objects.slug }} 
     ------
{% endfor %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top