# \_\_str\_\_ function not working for my model

**URL:** <https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085>\
**Category:** Using Django\
**Created:** [August 4, 2021, 12:34pm UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085 "2021-08-04T12:34:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Invito](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/invito/32/5364_2.png) [@Invito](https://forum.djangoproject.com/u/Invito)\
**Post date:** [August 4, 2021, 12:34pm UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085/1 "2021-08-04T12:34:02Z")

</div>

```auto
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

---

<div class="post-metadata">

**Author:** ![awtimmering](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/awtimmering/32/4109_2.png) [@awtimmering](https://forum.djangoproject.com/u/awtimmering)\
**Post date:** [August 4, 2021, 12:46pm UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085/2 "2021-08-04T12:46:20Z")

</div>

> [@Invito](#):
>
> `def ___str__ (self):`

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?

---

<div class="post-metadata">

**Author:** ![Invito](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/invito/32/5364_2.png) [@Invito](https://forum.djangoproject.com/u/Invito)\
**Post date:** [August 4, 2021, 12:50pm UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085/3 "2021-08-04T12:50:11Z")

</div>

Thank you! I’m so dumb 😂

---

<div class="post-metadata">

**Author:** ![pmasonBWC](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pmasonbwc/32/5135_2.png) [@pmasonBWC](https://forum.djangoproject.com/u/pmasonBWC)\
**Post date:** [August 5, 2021, 10:43am UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085/4 "2021-08-05T10:43:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 5, 2021, 11:17am UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085/5 "2021-08-05T11:17:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pmasonBWC](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pmasonbwc/32/5135_2.png) [@pmasonBWC](https://forum.djangoproject.com/u/pmasonBWC)\
**Post date:** [August 5, 2021, 11:33am UTC](https://forum.djangoproject.com/t/str-function-not-working-for-my-model/9085/6 "2021-08-05T11:33:29Z")

</div>

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