Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ================views.py=======================
- class AdsList(ListView):
- model = Ads
- template_name = 'main/ad_list.html'
- context_object_name = 'ads'
- paginate_by = 5
- extra_context = {'all_tags': Tag.objects.all()}
- def get_queryset(self):
- tag = self.request.GET.get('tag')
- if tag is None:
- return Ads.objects.all()
- return Ads.objects.filter(tags__name=tag)
- ================urls.py=========================
- path('ads/', views.AdsList.as_view(), name='ads'),
- ================template========================
- {% for tag in all_tags %}
- <a href="?tag={{ tag.name }}" class="list-group-item">{{ tag.name }} </a>
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement