File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -878,6 +878,7 @@ def _get_polymorphic_base(bases):
878878
879879 # some validation
880880 col_names = set ()
881+ column_dict_by_db_field = OrderedDict ()
881882 for v in column_dict .values ():
882883 # check for duplicate column names
883884 if v .db_field_name in col_names :
@@ -887,6 +888,7 @@ def _get_polymorphic_base(bases):
887888 if v .clustering_order and v .clustering_order .lower () not in ('asc' , 'desc' ):
888889 raise ModelException ("invalid clustering order {0} for column {1}" .format (repr (v .clustering_order ), v .db_field_name ))
889890 col_names .add (v .db_field_name )
891+ column_dict_by_db_field [v .db_field_name ] = v
890892
891893 # create db_name -> model name map for loading
892894 db_map = {}
@@ -897,6 +899,7 @@ def _get_polymorphic_base(bases):
897899 attrs ['_columns' ] = column_dict
898900 attrs ['_primary_keys' ] = primary_keys
899901 attrs ['_defined_columns' ] = defined_columns
902+ attrs ['_column_dict_by_db_field' ] = column_dict_by_db_field
900903
901904 # maps the database field to the models key
902905 attrs ['_db_map' ] = db_map
Original file line number Diff line number Diff line change @@ -780,7 +780,13 @@ class ModelQuerySet(AbstractQuerySet):
780780 def _validate_select_where (self ):
781781 """ Checks that a filterset will not create invalid select statement """
782782 # check that there's either a = or IN relationship with a primary key or indexed field
783- equal_ops = [self .model ._columns .get (w .field ) for w in self ._where if isinstance (w .operator , EqualsOperator )]
783+ equal_ops = []
784+ for w in self ._where :
785+ if isinstance (w .operator , EqualsOperator ):
786+ op = self .model ._columns .get (w .field )
787+ if op == None :
788+ op = self .model ._column_dict_by_db_field .get (w .field )
789+ equal_ops .append (op )
784790 token_comparison = any ([w for w in self ._where if isinstance (w .value , Token )])
785791 if not any ([w .primary_key or w .index for w in equal_ops ]) and not token_comparison and not self ._allow_filtering :
786792 raise QueryException ('Where clauses require either a "=" or "IN" comparison with either a primary key or indexed field' )
You can’t perform that action at this time.
0 commit comments