first_instance here is a string. So when it tests for truth in the template, it will always return as True because it exists. You can cast this as an int and it should work fine.