Ticket #12239: bug12239.diff

File bug12239.diff, 1.8 KB (added by aroy, 15 years ago)
  • django/db/models/fields/__init__.py

     
    875875            return None
    876876        return int(value)
    877877
     878    def get_prep_lookup(self, lookup_type, value):
     879        if lookup_type == 'gte':
     880            return value
     881        return super(IntegerField, self).get_prep_lookup(lookup_type, value)
     882
    878883    def get_internal_type(self):
    879884        return "IntegerField"
    880885
  • tests/regressiontests/queries/models.py

     
    418418>>> Number.objects.filter(Q(num__gt=7) & Q(num__lt=12) | Q(num__lt=4))
    419419[<Number: 8>]
    420420
     421Bug #12239
     422Float was being rounded to integer on gte queries on integer field.  Tests
     423show that both gte and lte work as desired.  Note that the fix changes
     424get_prep_lookup for gte queries only.
     425>>> Number.objects.filter(num__gte=11.9)
     426[<Number: 12>]
     427>>> Number.objects.filter(num__gte=12)
     428[<Number: 12>]
     429>>> Number.objects.filter(num__gte=12.0)
     430[<Number: 12>]
     431>>> Number.objects.filter(num__gte=12.1)
     432[]
     433>>> Number.objects.filter(num__gte=12.9)
     434[]
     435>>> Number.objects.filter(num__lte=11.9)
     436[<Number: 4>, <Number: 8>]
     437>>> Number.objects.filter(num__lte=12)
     438[<Number: 4>, <Number: 8>, <Number: 12>]
     439>>> Number.objects.filter(num__lte=12.0)
     440[<Number: 4>, <Number: 8>, <Number: 12>]
     441>>> Number.objects.filter(num__lte=12.1)
     442[<Number: 4>, <Number: 8>, <Number: 12>]
     443>>> Number.objects.filter(num__lte=12.9)
     444[<Number: 4>, <Number: 8>, <Number: 12>]
     445
    421446Bug #7872
    422447Another variation on the disjunctive filtering theme.
    423448
Back to Top