[Answered ]-Create custom views for django-tagging

2👍

Considering Element is your class from your model.

In your view

from django.db import models
from tagging.fields import TagField
from tagging.models import Tag

def myView(request,slug,tag){
   user = request.user
   element = Element.objects.get(slug=slug)
   #getting all tags added on the given element
   tags = Tag.objects.get_for_object(element)
   #getting all elements containing the given tag
   taggedElement = Element.objects.filter(tags__contains=tag)

  template = "elements/elements.html";

    context = {
        'taggedElement':taggedElement ,
        'tags':tags,
        'user':user,
    }

  return render_to_response( template, context, context_instance=RequestContext(request))
}

Then in your template (elements.html)

{% for tag in tags%}
<div class="tag">{{tag}}</div>
{% endfor %}

Leave a comment