def band_search_json(request): q = request.GET['q'] searchterm = normalize_string( q ) if searchterm=='': matches = [] else: bands = Band.objects.all().filter(name_normalized__startswith=searchterm)[:20] matches = [band.name for band in bands] resp_obj = {'q':q,'matches':matches} return HttpResponse( json.dumps(resp_obj) )
def person_search_json(request): q = request.GET['q'] searchterm = normalize_string( q ) if searchterm=='': matches = [] else: people = Person.objects.all().filter(name_normalized__startswith=searchterm)[:20] matches = [person.name for person in people] resp_obj = {'q':q,'matches':matches} return HttpResponse( json.dumps(resp_obj) )
def __init__(self, *args, **kwargs): models.Model.__init__(self, *args, **kwargs) self.name_normalized = normalize_string(self.name)
def fixbands(request): for band in Band.objects.all(): band.name_normalized = normalize_string(band.name) band.save() return HttpResponse('success')
def fixpeople(request): for person in Person.objects.all(): person.name_normalized = normalize_string(person.name) person.save() return HttpResponse('success')