code: def has_joins(queryset):
      
      for join in six.itervalues(queryset.query.alias_map):
          if join.join_type:
              return True
      return False
docs: Return True iff. a queryset includes joins.
  
      If this is the case, it is possible for the queryset
      to return duplicate results.