code: def generate_query(self):
          
          query = Q()
          ORed = []
          for form in self._non_deleted_forms:
              if not hasattr(form, 'cleaned_data'):
                  continue
              if form.cleaned_data['field'] == "_OR":
                  ORed.append(query)
                  query = Q()
              else:
                  query = query & form.make_query()
          if ORed:
              if query:  # add last query for OR if any
                  ORed.append(query)
              query = reduce(operator.or_, ORed)
          return query
docs: Reduces multiple queries into a single usable query