Welcome to the lesson on creating the To-Do model in Django. In this lesson, we will focus on building the foundational model for our To-Do application. The goal is to help you understand how to define a model in Django, set up corresponding views, and map these views to URLs so that you can create and display To-Do items via an API endpoint.
Models in Django are used to define the structure of your database tables. By the end of this lesson, you will be able to create a Todo model with fields for the task description and its completion status and expose this data through an API that you can test.
In Django, a model defines the structure of your database tables. Each model is a Python class that subclasses django.db.models.Model. It contains fields that represent the columns of the table. Let's create our Todo model.
Here is the code for creating the basic Todo model in models.py:
task: This field is aCharField, which is used to store text data. Note thatCharFieldhave a parameter. We set the to 200, which means this field can store up to 200 characters.
