(self, *models)
return self.select_subclasses(*models).extra(where=[' OR '.join(where_queries)])
Fetch only objects that are instances of the provided model(s).
Fetch only objects that are instances of the provided model(s).
Fetch only objects that are instances of the provided model ( s ) .
def instance_of(self, *models):
        """
        Fetch only objects that are instances of the provided model(s).
        """
        # If we aren't already selecting the subclasess, we need
        # to in order to get this to work.

        # How can we tell if we are not selecting subclasses?

        # Is it safe to just apply .select_subclasses(*models)?

        # Due to https://code.djangoproject.com/ticket/16572, we
        # can't really do this for anything other than children (ie,
        # no grandchildren+).
        where_queries = []
        for model in models:
            where_queries.append('(' + ' AND '.join([
                '"{}"."{}" IS NOT NULL'.format(
                    model._meta.db_table,
                    field.attname,  # Should this be something else?
                ) for field in model._meta.parents.values()
            ]) + ')')

        return self.select_subclasses(*models).extra(where=[' OR '.join(where_queries)])
def instance_of ( self , * models ) : # If we aren't already selecting the subclasess, we need # to in order to get this to work. # How can we tell if we are not selecting subclasses? # Is it safe to just apply .select_subclasses(*models)? # Due to https://code.djangoproject.com/ticket/16572, we # can't really do this for anything other than children (ie, # no grandchildren+). where_queries = [ ] for model in models : where_queries . append ( '(' + ' AND ' . join ( [ '"{}"."{}" IS NOT NULL' . format ( model . _meta . db_table , field . attname , # Should this be something else? ) for field in model . _meta . parents . values ( ) ] ) + ')' ) return self . select_subclasses ( * models ) . extra ( where = [ ' OR ' . join ( where_queries ) ] )