From the course: Learning Django
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Implement model and fields
- [Instructor] To begin implementing our models, we'll open our text editor to the models.py file in our adoptions app. First, I'll unfold the wisdompets folder. Then the adoptions folder and double-click the models.py file. The first line in this file is an import statement of the model's module from django.db. This contains the base class called model that we'll need to inherit from for each model that we define. Now I'll remove this comment that's no longer needed. Let's start with a model for storing our pet information. So we'll create a class called Pet, and we'll make it inherit from models.Model. Next, I'll start providing the fields for this model. Let's start with the pet's name, and we'll use a CharField. For a pet's name, a reasonable max length might be about 100 characters. So we'll set max_length=100. Now I'd like to define a few more CharFields for the submitter, species and breed of the pet. So I'll…
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
-
-
-
-