InterviewSolution
| 1. |
What are models in Django? |
|
Answer» A model in Django refers to a CLASS that MAPS to a database table or database collection. Each attribute of the Django model class represents a database field. They are defined in app/models.py Example: from django.db import modelsclass SampleModel(models.Model):field1 = models.CharField(max_length = 50)field2 = models.IntegerField()class Meta:db_table = “sample_model”Every model inherits from django.db.models.Model The metaclass helps you set things like available permissions, singular and plural VERSIONS of the name, associated database table name, whether the model is abstract or not, etc. |
|