Search code examples
pythondjangodjango-2.0

How to pass more than two parameters in a queryset in Django?


I hope my question is understood

For example, I have this model

class Area(models.Model):
  area_id = models.IntegerField()
  name = models.CharField()
  last_name = models.CharField()
  short_name = models.CharField()

I want to make a query with several parameters

If I do not find the first one, look for it for the second and so with the third

filter_areas = Area.objects.filter(area_id=3 | name='area_name' | short_name='are')

Like to an or |


Solution

  • You can use Q object here:

    from django.db.models import Q
    
    Area.objects.filter(Q(area_id=1)| Q(name='name') | Q(short_name='are'))