A Django model defines no __str__, so the admin and shell show it as Model object (1)
What it finds
Django shows model instances by their __str__ in the admin, in form choices and in the shell; without one they read as Book object (17). Checked are classes whose base is models.Model or Model, unless their Meta makes them abstract.
From the rule's source, django_model_without_str.rs.
from django.db import models class Book(models.Model):tx0 reports: this model has no __str__ title = models.CharField(max_length=100) class Author(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name class Base(models.Model): class Meta: abstract = True Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:django-model-without-str" = "note"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:django-model-without-str] reason="..."tx0 explain tx0/python:django-model-without-str shows the same in the terminal. Found a false positive? Report it.