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

Implement model and fields

From the course: Learning Django

Start my 1-month free trial

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…

Contents