Remove whitespace from filteting url django tastypie -


i have few urls using filtering. when values using specific urls get

  1. api/v1/labels/?brand_city__location__state_or_country=new%20york

  2. api/v1/labels/?brand_city__city=novi%20sad

alot of values being used have space inbetween words. how can remove %20 spaces , have url cleaner return:

desired: api/v1/labels/?brand_city__city=novi sad no %20 present

api.py

class locationresource(modelresource):     class meta:          filtering =  {             "state_or_country":         }  class cityresource(modelresource):      location = fields.foreignkey(locationresource, 'location', full=true)      class meta:          filtering =  {             "city": all,             "location": all_with_relations         }  class labelresource(modelresource):      brand_city = fields.foreignkey(cityresource, 'brand_city', full=true)      class meta:          filtering = {            "brand_category": all,            "brand_city": all_with_relations         } 

snippet response

{   "labels": [     {       "brand_city": {         "city": "manhattan",         "location": {           "location_choices": "state",           "state_or_country": "new york"         }       }     }   ],   "meta": {     "limit": 6,     "next": null,     "offset": 0,     "previous": null,     "total_count": 1   } } 

check out python function urllib2.unquote

# can convert urls using urlib2 library path = urllib2.unquote("api/v1/labels/?brand_city__location__state_or_country=new%20york") 

also, unquote, function unquote_plus can used replaces plus signs spaces, required unquoting html form values. use according requirement


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) -