Creating our first model
Working with databases in Django involves working with models. A model contains the fields and behaviors of the data we want to store. Commonly, each model maps a database table. We can create models such as blog posts, movies, and users, and Django turns these models into a database table for us.
Here are the Django model basics:
- Each model is a class that extends
django.db.models.Model. - Each model attribute represents a database column.
- With all of this, Django provides us with a set of useful methods to create, update, read, and delete (CRUD) model information from a database.
/movie/models.py
In /movie, we have the models.py file, where we create our models for the movie app. Open that file and fill it in with the following:
from django.db import models class Movie(models.Model): Â Â Â Â title = models.CharField(max_length=100) Â Â Â Â description = models.CharField(max_length=250) Â &...