Skip to content

Commit

Permalink
fix decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
atarkowska committed May 4, 2018
1 parent 1bc9329 commit 46ee280
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions emgapi/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from decimal import Decimal

from django import forms
from django.db.models import Q
from django.db.models import FloatField
Expand Down Expand Up @@ -359,39 +361,31 @@ def filter_geo_loc_name(self, qs, name, value):
help_text='Latitude greater/equal then value')

def filter_latitude_gte(self, qs, name, value):
return qs.annotate(
latitude_cast=Cast('latitude', FloatField())) \
.filter(latitude_cast__gte=float(value))
return qs.filter(latitude__gte=Decimal(str(value)))

latitude_lte = django_filters.NumberFilter(
method='filter_latitude_lte', distinct=True,
label='Latitude less/equal then value',
help_text='Latitude less/equal then value')

def filter_latitude_lte(self, qs, name, value):
return qs.annotate(
latitude_cast=Cast('latitude', FloatField())) \
.filter(latitude_cast__lte=float(value))
return qs.filter(latitude__lte=Decimal(str(value)))

longitude_gte = django_filters.NumberFilter(
method='filter_longitude_gte', distinct=True,
label='Longitude greater/equal then value',
help_text='Longitude greater/equal then value')

def filter_longitude_gte(self, qs, name, value):
return qs.annotate(
longitude_cast=Cast('longitude', FloatField())) \
.filter(longitude_cast__gte=float(value))
return qs.filter(longitude__gte=Decimal(str(value)))

longitude_lte = django_filters.NumberFilter(
method='filter_longitude_lte', distinct=True,
label='Longitude less/equal then value',
help_text='Longitude less/equal then value')

def filter_longitude_lte(self, qs, name, value):
return qs.annotate(
longitude_cast=Cast('longitude', FloatField())) \
.filter(longitude_cast__lte=float(value))
return qs.filter(longitude__lte=Decimal(str(value)))

study_accession = django_filters.CharFilter(
method='filter_study_accession', distinct=True,
Expand Down

0 comments on commit 46ee280

Please sign in to comment.