Django: Getting Started Transcripts
Chapter: Django ORM and Databases
Lecture: Improved debug info for books

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The debug info in the rebel wasn't too helpful. Fortunately, there is a way of defining it for yourself.
0:07 Let me just add a couple of lines here to the catalog models.py file. If you haven't seen double underscore str before
0:19 which is pronounced dunder string by the way. This is a special method in Python that gets called when you convert an object to a string.
0:27 Django uses this when you query things as well as in the Django admin. If you don't want the less helpful book object bracket one,
0:36 you'll want to overload this method like I've done here. The F string online 18 contains the fact that this is a book object with the
0:45 given id, title, and authors id. Note that you can get at the author models fields through the book's author atribute.
0:53 I'm doing that here showing the author's primary key inside of Dunder string. With that change in place, let me go back into the shell.


Talk Python's Mastodon Michael Kennedy's Mastodon