Ensure Django Model Classes Implement a __str__ Method

This commit is contained in:
pixeebot[bot]
2025-02-14 03:17:53 +00:00
committed by GitHub
parent c19aaf2f4b
commit f56c4a0b37
2 changed files with 10 additions and 0 deletions

View File

@@ -55,3 +55,8 @@ class PageView(models.Model):
return model_class.objects.filter(pk__in=id_list).order_by(preserved)
return model_class.objects.none()
def __str__(self):
model_name = self.__class__.__name__
fields_str = ", ".join((f"{field.name}={getattr(self, field.name)}" for field in self._meta.fields))
return f"{model_name}({fields_str})"