[Answered ]-Python Django query error: Can't convert 'method' object to str implicitly

2👍

def __str__(self):
    return 'City: ' + self.get_city_en()

You want the result of the function call. What you’re doing is trying to concatenate a function with a string. Consider:

def foo():
  return "test"

print foo    # <function foo at 0x1052b0aa0>
print foo()  # "Test"

0👍

Got my answer thanks to @Kit Sunde. Had 2 mistakes. Corrected code below:

return 'City: ' + self.get_city_en()


searched_city = CityLanguage.objects.filter(city_language__exact='EN', city__exact=self)

I was trying to reference the CityLanguage table by specifying models.CityLanguage which is incorrect. Should just be CityLanguage.

Leave a comment