Ticket #27736: django-db-models-lookups.patch

File django-db-models-lookups.patch, 5.2 KB (added by Mads Jensen, 8 years ago)
  • django/db/models/lookups.py

    diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
    index 5429204..1dddcc8 100644
    a b class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin):  
    235235        return sql, tuple(params)
    236236
    237237
     238@Field.register_lookup
    238239class Exact(FieldGetDbPrepValueMixin, BuiltinLookup):
    239240    lookup_name = 'exact'
    240241
    241242
    242 Field.register_lookup(Exact)
    243 
    244 
     243@Field.register_lookup
    245244class IExact(BuiltinLookup):
    246245    lookup_name = 'iexact'
    247246    prepare_rhs = False
    class IExact(BuiltinLookup):  
    253252        return rhs, params
    254253
    255254
    256 Field.register_lookup(IExact)
    257 
    258 
     255@Field.register_lookup
    259256class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup):
    260257    lookup_name = 'gt'
    261258
    262259
    263 Field.register_lookup(GreaterThan)
    264 
    265 
     260@Field.register_lookup
    266261class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup):
    267262    lookup_name = 'gte'
    268263
    269264
    270 Field.register_lookup(GreaterThanOrEqual)
    271 
    272 
     265@Field.register_lookup
    273266class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup):
    274267    lookup_name = 'lt'
    275268
    276269
    277 Field.register_lookup(LessThan)
    278 
    279 
     270@Field.register_lookup
    280271class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup):
    281272    lookup_name = 'lte'
    282273
    283274
    284 Field.register_lookup(LessThanOrEqual)
    285 
    286 
    287275class IntegerFieldFloatRounding(object):
    288276    """
    289277    Allow floats to work as query values for IntegerField. Without this, the
    class IntegerFieldFloatRounding(object):  
    295283        return super(IntegerFieldFloatRounding, self).get_prep_lookup()
    296284
    297285
     286@IntegerField.register_lookup
    298287class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual):
    299288    pass
    300289
    301290
    302 IntegerField.register_lookup(IntegerGreaterThanOrEqual)
    303 
    304 
     291@IntegerField.register_lookup
    305292class IntegerLessThan(IntegerFieldFloatRounding, LessThan):
    306293    pass
    307294
    308295
    309 IntegerField.register_lookup(IntegerLessThan)
    310 
    311 
    312296class DecimalComparisonLookup(object):
    313297    def as_sqlite(self, compiler, connection):
    314298        lhs_sql, params = self.process_lhs(compiler, connection)
    class DecimalLessThanOrEqual(DecimalComparisonLookup, LessThanOrEqual):  
    343327    pass
    344328
    345329
     330@Field.register_lookup
    346331class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
    347332    lookup_name = 'in'
    348333
    class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):  
    403388        return ''.join(in_clause_elements), params
    404389
    405390
    406 Field.register_lookup(In)
    407 
    408 
    409391class PatternLookup(BuiltinLookup):
    410392
    411393    def get_rhs_op(self, connection, rhs):
    class PatternLookup(BuiltinLookup):  
    425407            return super(PatternLookup, self).get_rhs_op(connection, rhs)
    426408
    427409
     410@Field.register_lookup
    428411class Contains(PatternLookup):
    429412    lookup_name = 'contains'
    430413    prepare_rhs = False
    class Contains(PatternLookup):  
    436419        return rhs, params
    437420
    438421
    439 Field.register_lookup(Contains)
    440 
    441 
     422@Field.register_lookup
    442423class IContains(Contains):
    443424    lookup_name = 'icontains'
    444425    prepare_rhs = False
    445426
    446427
    447 Field.register_lookup(IContains)
    448 
    449 
     428@Field.register_lookup
    450429class StartsWith(PatternLookup):
    451430    lookup_name = 'startswith'
    452431    prepare_rhs = False
    class StartsWith(PatternLookup):  
    458437        return rhs, params
    459438
    460439
    461 Field.register_lookup(StartsWith)
    462 
    463 
     440@Field.register_lookup
    464441class IStartsWith(PatternLookup):
    465442    lookup_name = 'istartswith'
    466443    prepare_rhs = False
    class IStartsWith(PatternLookup):  
    472449        return rhs, params
    473450
    474451
    475 Field.register_lookup(IStartsWith)
    476 
    477 
     452@Field.register_lookup
    478453class EndsWith(PatternLookup):
    479454    lookup_name = 'endswith'
    480455    prepare_rhs = False
    class EndsWith(PatternLookup):  
    486461        return rhs, params
    487462
    488463
    489 Field.register_lookup(EndsWith)
    490 
    491 
     464@Field.register_lookup
    492465class IEndsWith(PatternLookup):
    493466    lookup_name = 'iendswith'
    494467    prepare_rhs = False
    class IEndsWith(PatternLookup):  
    500473        return rhs, params
    501474
    502475
    503 Field.register_lookup(IEndsWith)
    504 
    505 
     476@Field.register_lookup
    506477class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
    507478    lookup_name = 'range'
    508479
    class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):  
    510481        return "BETWEEN %s AND %s" % (rhs[0], rhs[1])
    511482
    512483
    513 Field.register_lookup(Range)
    514 
    515 
     484@Field.register_lookup
    516485class IsNull(BuiltinLookup):
    517486    lookup_name = 'isnull'
    518487    prepare_rhs = False
    class IsNull(BuiltinLookup):  
    525494            return "%s IS NOT NULL" % sql, params
    526495
    527496
    528 Field.register_lookup(IsNull)
    529 
    530 
     497@Field.register_lookup
    531498class Search(BuiltinLookup):
    532499    lookup_name = 'search'
    533500    prepare_rhs = False
    class Search(BuiltinLookup):  
    543510        return sql_template, lhs_params + rhs_params
    544511
    545512
    546 Field.register_lookup(Search)
    547 
    548 
     513@Field.register_lookup
    549514class Regex(BuiltinLookup):
    550515    lookup_name = 'regex'
    551516    prepare_rhs = False
    class Regex(BuiltinLookup):  
    560525            return sql_template % (lhs, rhs), lhs_params + rhs_params
    561526
    562527
    563 Field.register_lookup(Regex)
    564 
    565 
     528@Field.register_lookup
    566529class IRegex(Regex):
    567530    lookup_name = 'iregex'
    568531
    569532
    570 Field.register_lookup(IRegex)
    571 
    572 
    573533class YearLookup(Lookup):
    574534    def year_lookup_bounds(self, connection, year):
    575535        output_field = self.lhs.lhs.output_field
Back to Top