def get_redirect_url(self, *args, **kwargs): q = self.request.GET.get('q', None) try: city = City.get_by_crc(q) except City.DoesNotExist: raise Http404 return reverse('category-list-html', args=[city.tr_url])
def by_city(self, city): # city may be a pk, a url, a crc, or a City instance. if isinstance(city, int): city = City.objects.get(pk=city) elif isinstance(city, str) and city.count(', ') == 2: city = City.get_by_url(city) elif isinstance(city, str) and city.count('/') == 2: city = City.get_by_crc(city) return self.published_only().filter(city=city)
def _get_city_by_crc(crc): """Return the database object found by the string from the <input> field.""" return City.get_by_crc(crc)