I am new to Python and have inherited the code base from another developer. I am getting a MultipleObjectsReturned at / get() returned more than one City -- it returned 2! error.
In the code below, I changed the get to filter and checked that there are no duplicates in the database.
context['count_promotions'] = count_promotions = promotions.count()
count_cities = 0
count_products = 0
for promotion in promotions:
for location in promotion.store.all().values_list('city__name',
flat=True).order_by('city__name').distinct('city__name'):
count_cities += 1
primary_key = City.objects.filter(name__icontains=location).pk
province = Region.objects.filter(city__name__icontains=location)
new_text = location.replace(',', '')
almost_finished = new_text.replace('&', '')
finished = almost_finished.replace(' ', '-')
store_locations.append({
'pk': primary_key,
'city' : finished,
'province' : province.name,
})
What else can I check to resolve the issue?
Thanks in advance.