A
A
Anton2018-09-20 22:33:21
Django
Anton, 2018-09-20 22:33:21

Django ORM how to make a fetch?

class Event(models.Model):
  name = ...
        ....


class Person(models.Model):
  name = ...
  events = models.ManyToManyField(Event, blank=True)
        ....

could you tell me how to select Event objects only those that must contain at least one Person object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2018-09-20
@anttoon

Thanks toster.ru, Found the solution here
Event.objects.filter(id__in=Person.objects.all().values(events'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question