| 454 | | === __repr__() model method is replaced by __str__() === |
| 455 | | |
| 456 | | Or seems to be afaics. Hm, how do I get those underscores to display as underscores instead of underline formatting? |
| | 454 | === `__repr__()` model method is replaced by `__str__()` === |
| | 455 | |
| | 456 | You should use `__str__()` where `__repr__()` was formerly used, i.e., as a string representation of the model. |
| | 457 | |
| | 458 | `__repr__()` returns to its standard Python purpose of returning a string suitable for debugging purposes (e.g., `<ObjectName more_info>`); unless you want to customize the returned string, explicitly overriding `__repr__` in a model class is unnecessary. |
| | 459 | |
| | 460 | For example:: |
| | 461 | |
| | 462 | {{{ |
| | 463 | class BlogPost(models.Model): |
| | 464 | |
| | 465 | [...] |
| | 466 | |
| | 467 | def __repr__(self): |
| | 468 | return '''<BlogPost title="%s" comments_enabled=%s>''' % (self.title, self.comments_enabled) |
| | 469 | |
| | 470 | def __str__(self): |
| | 471 | return self.title |
| | 472 | }}} |
| | 473 | |