Django: Getting Started Transcripts
Chapter: Django ORM and Databases
Lecture: The Django REPL

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Django has its own version of the Python Rebel. Using this instead of the rebel means that a bunch of environmental stuff
0:07 Django needs is already taken care of this means you can skip a bunch of steps you'd otherwise have to do to tell Django where the project lives.
0:16 You get into the Django Rebel by running the shell management command. If you're on Windows remember you'll have to be less lazy than I am and run
0:24 the full Python managed shell instead of using the eunuchs dot slash shortcut. Total aside, but if you're going to be doing a lot of Python and Django
0:35 in the Windows world, I'd encourage you to learn how to use the Windows subsystem for Linux.
0:40 It allows you to run a Linux instance inside of your windows, giving you the best of both worlds, 99% of the time you're production.
0:48 Django code is going to live on a UNIX based OS. So you're more likely to solve hosting problems before they happen if you're coding in
0:56 a similar environment. Because it runs under Windows, you can get at all the same files and use all the same tools you're used to,
1:03 like I said, the best of both worlds. Anyhow, here I am inside of the Django Shell in order to play with our models, the first step is to import them.
1:17 Now, I'll create an author, there's a bunch going on here. Remember when I said that every model inherits from models.model class.
1:31 One of the reasons for that is to give you access to the query manager. The query manager is available as an attribute on your model named objects.
1:41 This query manager has a bunch of methods which allow you to interface with the database
1:45 The create method creates an object and the corresponding row in the database.
1:52 The call to create requires the named arguments for any of the required fields defined in the object.
1:59 In this case, I'm creating an author object, sending in the last name and year of birth.
2:06 Looking at the Dickens object, you get a typically terse bit of rebel printing
2:11 telling you that Dickens is an author object and the one in brackets is the primary key or object I. D.
2:21 You can get at the fields in the object through dot access. The last name field contains Dickens. That's good it should.

Talk Python's Mastodon Michael Kennedy's Mastodon