python - Tastypie decimal and datetime filters not working -


the following lte , gte filter queries returns 0 objects:

curl http://localhost/river/river/?runoff__lte=100.0&runoff__gte=150.0 curl http://localhost/river/river/?runoff__lte=100&runoff__gte=150 http://localhost/river/river/?dt_timestamp__lte=2015-01-01t03:00&dt_timestamp__gte=2015-01-07t18:00&format=json 

here's models.py

class river(models.model):     dt_timestamp = models.datetimefield()     stage = models.decimalfield(max_digits=10, decimal_places=3, blank=true, null=true)     runoff = models.decimalfield(max_digits=10, decimal_places=3) 

api.py

class riverresults(modelresource):     class meta:         queryset = river.objects.all()         resource_name = 'river'         authorization = authorization()         filtering = {             'user': all_with_relations,             'dt_timestamp':             'stage': all,             'runoff': all,         } 

in settings.py use_tz = false

am running postgresql 9.3, django 1.6 , tastypie 0.12.2. not sure doing wrong.

regards, allan

i guess need select rivers runoff between 100 , 150 or dt_timestamp between 2015-01-01t03:00 , 2015-01-07t18:00. in case try:

http://localhost/river/river/?runoff__gte=100.0&runoff__lte=150.0 http://localhost/river/river/?runoff__gte=100&runoff__lte=150 http://localhost/river/river/?dt_timestamp__gte=2015-01-01t03:00&dt_timestamp__lte=2015-01-07t18:00 

if need select rivers runoff lower 100 or greater 150, need overwrite build_filters function:

def build_filters(self, filters=none):     qs_filters = super(riverresults, self).build_filters(filters)     if filters.get('runoff_not_between') not none:         runoff_not_between = filters.get('runoff_not_between').split(',')         qs_filters = qs_filters.update(q(runoff__lte=runoff_not_between[0]) | q(runoff__gte=runoff_not_between[1]))     return qs_filters 

and use:

http://localhost/river/river/?runoff_not_between=100.0,150.0 http://localhost/river/river/?runoff_not_between=100,150 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -