![]() |
VOOZH | about |
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. Do also go through Django Models prior to moving ahead.
Model Meta is basically the inner class of your model class. Model Meta is basically used to change the behavior of your model fields like changing order options,verbose_name, and a lot of other options. It's completely optional to add a Meta class to your model. In order to use model meta you have to add class Meta in your model as shown below as follows:
class student(models.Model): class Meta: options........
Model Meta has a lot of options that you can give your model in its internal class meta
1. abstract
If abstract = True, this model will be an abstract base class
2. app_label
If a model is defined outside of applications in INSTALLED_APPS, it must declare which app it belongs to:
3. verbose_name
verbose_name is basically a human-readable name for your model
4. ordering
Ordering is basically used to change the order of your model fields.
Add ordering like this [-1] it changes the order in descending order
5. proxy
If we add proxy = True a model which subclasses another model will be treated as a proxy model
This is how can we make a proxy model.
6. permissions
Extra permissions to enter into the permissions table when creating this object. Add, change, delete and view permissions are automatically created for each model.
You can add extra permission inside the list.
7. db_table
We can overwrite the table name by using db_table in meta class.
This will change the table name to X.
8. get_latest_by
It returns the latest object in the table based on the given field, used for typically DateField, DateTimeField, or IntegerField.
Return the latest by ascending order_date.