Skip to content

Instantly share code, notes, and snippets.

@gileno
Created February 19, 2016 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gileno/c539232c3e565cfa25e1 to your computer and use it in GitHub Desktop.
Save gileno/c539232c3e565cfa25e1 to your computer and use it in GitHub Desktop.
Django Filter
def minha_view(request):
marca = request.GET.get("marca", "")
if marcar:
context["brands_list"] = Post.objects.filter(is_active=True, brands__exact='MARCA01').order_by('created_date')
else:
context["brands_list"] = Post.objects.filter(is_active=True).order_by('created_date')
@HigorMonteiro
Copy link

views.py

class BrandsTemplateView(TemplateView):
    template_name = 'core/brands.html'

    def get_context_data(self, **kwargs):
        context = super(BrandsTemplateView, self).get_context_data(**kwargs)
        marca = self.request.GET.get('marca')
        context["brands_list"] = Post.objects.filter(is_active=True).order_by('created_date')
        if marca:
            context["brands_list"] = context["brands_list"].filter(brands__exact=marca)
        assert isinstance(context, object)
        return context

@HigorMonteiro
Copy link

index.html


 <div class="container">
      <div class="col-md-4 text-center"><a href="{% url 'brands' %}?marca=MARCA01"><img src="{{ MEDIA_URL }}static/imagens/img01.png" width="316" height="17" class="imagem logo_maior"></a></div>
      <div class="col-md-4 text-center"><a href="{% url 'brands' %}?marca=MARCA01"><img src="{{ MEDIA_URL }}static/imagens/img02.png" width="220" height="54" class="imagem"></a></div>
      <div class="col-md-4 text-center"><a href="{% url 'brands' %}?marca=MARCA01"><img src="{{ MEDIA_URL }}static/imagens/img03.png" width="178" height="49" class="imagem"></a></div>
    </div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment