0

How can I filter two parameter in django views ? for example my code is :

**Views : **

def products_filter(request, product, selling):
    all_product = Product.objects.filter(product=product).filter(selling=selling)
mosi
  • 39
  • 9
  • what do you want to achieve? your code is viable, if you want just another variant, then you can use also Product.objects.filter(product=product, selling=selling) – Andrey Maslov Jul 11 '20 at 19:40

1 Answers1

0

Try something like this

from django.db.models import Q

def products_filter(request, product, selling):
    all_product = Product.objects.filter(Q(product=product)| Q(selling=selling))
bkrop
  • 228
  • 2
  • 10
  • Can I use & symbol ? – mosi Jul 11 '20 at 19:47
  • I'm sorry, this question should help you: https://stackoverflow.com/questions/5542874/difference-between-filter-with-multiple-arguments-and-chain-filter-in-django – bkrop Jul 11 '20 at 19:52