1

I came across an error that was poorly explained when I wanted to customize the magic str function of my "ApiCall" model.

My Model :

FOO = 1
FOO2 = 2
FOO3 = 3
ROUTES = (
    (FOO, "foo"),
    (FOO2, "foo 2"),
    (FOO3, "foo 3"),
)


class ApiCall(TimeStampedModel):
    user = models.ForeignKey(MobileUser, on_delete=models.CASCADE)
    route = models.PositiveSmallIntegerField('foo', choices=ROUTES)

    def __str__(self):
        return f"... {self.get_route_display}"

Error :

RecursionError: maximum recursion depth exceeded while calling a Python object

1 Answer 1

1

The problem is very simple but I find it badly explained, you just have to add parenthesis when you call the get_route_display function. like this :

def __str__(self):
  return f"... {self.get_route_display()} ..."

PS: This function is automatically created from the "route" field in the model

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.