

from django.db import modelsĭateTimeOfPosting = models.DateTimeField(auto_now_add = True) When the objects of this model are retrieved, they will be present in this ordering. It’s used to define the ordering of objects of a model. This option takes a list of string values, which are model fields.

For example: if I do something as follows, the name of my model will be job in the database. This option is used to set the name that should be used to identify the table inside the database. Inside the database, only the Teacher and Student models will be created. Here, the Teacher and the Student models will have all the fields inside the Human model. Subject = models.CharField(max_length = 200) Gender = models.CharField(max_length = 50, choices = genders) Name = models.CharField(max_length = 200) One can use this option if there are multiple models with common fields. Models that are set as an abstract can only be inherited. Abstract classes are the ones that can’t be instantiated and can only be extended or inherited. This option is used to define whether the model is abstract or not they work the same as abstract classes. The following are some of the commonly used meta options you can explore all the meta options here Django Meta Option - Abstract This class also comes with many options you can configure. Adding Meta classes to Django models is entirely optional. The Meta class can be used to define various things about the model such as the permissions, database name, singular and plural names, abstraction, ordering, and etc. The Meta class is an inner class, which means it’s defined inside the model as follows: from django.db import models Find out more about the Meta class in Django models in this article. If we have to add some data about the model itself, we use the Meta class.

In Django, we use Django Models to design our database’s tables and their fields. Metadata refers to a specific set of data that provides information about another data.
