__str__ function not working for my model

class Agent(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)

    def ___str__(self):
        return "hi"

It shows Agent object (2) in admin site

Just eye-balling this, it looks like you might have 3 underscores on the first side, where the “dunder” (double-underscore) functions are specified with precisely 2 underscores both on the left and right side. Could you try changing that?

Thank you! I’m so dumb :joy:

I’ve just done the same thing, but spotted it myself. I appreciate this is probably a question for JetBrains, but PyCharm in turn only uses the Django interpreter…why doesn’t this kind of basic syntax error get flagged and stopped when the service starts?

Because this isn’t a syntax error. It’s perfectly valid to define a function named ___str__. It shouldn’t be flagged as any kind of error.

Ah, yes…and str(self) is optional.