Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 |

like image 369
Alex Avatar asked Jan 28 '23 03:01

Alex


1 Answers

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'))
like image 92
ruddra Avatar answered Feb 02 '23 00:02

ruddra