4

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 |

Alex
  • 615
  • 8
  • 26

1 Answers1

8

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'))
ruddra
  • 50,746
  • 7
  • 78
  • 101