Django: Getting Started Transcripts
Chapter: Course conclusion
Lecture: Data object models

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Django comes with an ORM. That's object relational mapping, an abstraction layer that sits on top of your database.
0:08 It allows you to think about a group of objects rather than the underlying tables the information is stored in.
0:13 You create a data model object by inheriting from Djangos db.models.model class and declare fields which get mapped to columns in the database.
0:24 Django provides dozens of different field types and allows you to create foreign keys and many to many relationships between your models.
0:31 Some of the fields will even auto generate their content like a date time stamp.
0:36 You can further control how your data objects behave through the use of an inner class called meta. Within this class,
0:43 you can configure things like the default order of query results as well as how Django will refer to objects of this type inside of the admin web tool.
0:52 Speaking of the admin web tool, you can overload the dunder string method to make the objects appearance in the tool be
0:58 whatever makes the most sense for your project. A lot of the work you do in a web application is simply CRUD,
1:07 that's create, read, update and delete the four operations you need on your data objects.
1:12 To help you manage these operations, Django comes with an admin web tool that acts as a gooey interface to your ORM. With very little extra code,
1:21 you can create, view, edit and delete all of your data objects and their relations
1:25 You register a data object with the admin tool by declaring a model admin object in admin.py.
1:34 These classes also provide ways of changing the display of the various screens in the admin that relate to this object,
1:41 thus allowing you to customize what fields are shown in the object listing and provide links to other objects in the interface.


Talk Python's Mastodon Michael Kennedy's Mastodon