| 1. |
What is the Model in Django? |
|
Answer» In web application storing and retrieving information in the database is a common task. To PERFORM these requirements Django comes with database management features. These features allow two things, one is, design database schema and second is, manage the data in the database that is read, write, update, delete, query, etc.
In Django, database tables are called models and these models are created in the models.py file which is located in the Dango app directory. A MODEL is a python class. While defining model you need to give a class NAME, subclass it from Django's included models. Model class. from Django.db import models class Glass(models.Model):The model is valid only if it has one or more fields. Fields can be created by adding the attribute to the model class. from django.db import models class Bottle(models.Model): size = models.IntegerField() color = models.CharField(max_length=100)Here field name is 'size' and 'color'. models.IntegerField() is the instance for field class, and you are telling the database what kind of data you want to save in the field. |
|