Reputation: 819
What I need to do it's just replace some items from model before render. So just in each business.address
replace '||' with ", ". I'm trying to do like that:
def category(request, q):
businesses = Business.objects.filter(category_string__icontains=q)[:50]
for b in businesses:
if '||' in b.address:
b.address.replace('||', ', ')
print(b.address)
But I still see the same string without replacing. What's the reason?
Upvotes: 1
Views: 340
Reputation: 42017
Strings are immutable in Python; hence, str.replace
is not in-place.
You need to do the name binding (again):
b.address = b.address.replace('||', ', ')
Upvotes: 1