From the course: Learning Django
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Django fields
- [Instructor] Let's take a look at a rough sketch of what a Pet model definition will look like. We start by importing the models module from django.db. We define our Pet model by creating a class called Pet that inherits from model.Model. Inside this class, we will define various fields by creating attributes and assigning them to field instances such as the CharField. Each of these fields can take keyword arguments like max_length and blank. Now that we've seen the concepts behind Django models and an overview of how they're defined, we just need to dig into the details a bit and look at defining fields. Given that, let's look at some various field types. This is not an exhaustive list, but it shows some that we are likely to use. For textual data, there's the CharField and TextField. The CharField requires a max_length attribute and stores an amount of characters up to that length. The TextField differs in that the length…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Models, routing, views, and templates3m 55s
-
(Locked)
Django models1m 19s
-
(Locked)
Django fields3m 46s
-
(Locked)
Implement model and fields5m 24s
-
(Locked)
Django migrations6m 5s
-
(Locked)
Import CSV data6m 24s
-
(Locked)
Work with the Django admin7m 18s
-
(Locked)
Query data with the Django ORM6m 42s
-
-
-
-