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

Django fields

From the course: Learning Django

Start my 1-month free trial

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…

Contents