Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 863B

12345678910111213141516171819202122232425262728293031
  1. from django.conf import settings
  2. from django.utils.translation import ugettext_lazy as _
  3. from django.views.generic import ListView
  4. from .settings import TAGGED_ITEM_MODEL, TAG_MODEL
  5. class TagCanvasListView(ListView):
  6. template_name = 'taggit_templatetags2/tagcanvas_list.html'
  7. model = TAGGED_ITEM_MODEL
  8. def get_tag_id(self):
  9. return int(self.kwargs['tag_id'])
  10. def get_tag_object(self):
  11. return TAG_MODEL.objects.get(id=self.get_tag_id())
  12. def get_queryset(self):
  13. """
  14. Returns only the objects assigned to single tag.
  15. """
  16. return self.model._default_manager.filter(
  17. tag_id=self.get_tag_id())
  18. def get_context_data(self, **kwargs):
  19. context = super(TagCanvasListView, self).get_context_data(**kwargs)
  20. context['tag'] = self.get_tag_object()
  21. return context