0

I have been using django and used class Meta: a lot of times, actually what is the use of it?

for example , In django models

class Accounts(models.Model):

   ---some code here--- 

   class Meta:
       ordering = [-1]

In django forms

class AccountForm(forms.ModelForm):

   ---some code here--- 

   class Meta:
       fields = '__all__'
Muhammed Fayis
  • 215
  • 3
  • 9
  • 2
    Does this answer your question? [What is exactly Meta in Django](https://stackoverflow.com/questions/57241617/what-is-exactly-meta-in-django) – Abdul Aziz Barkat Jul 15 '22 at 10:07

2 Answers2

0

class Meta is basically the inner class. In Django, the use of the Meta class is simply to provide metadata to the ModelForm or the Model class. It is different from the metaclass of a Class in Python.

Muhammed Fayis
  • 215
  • 3
  • 9
0

class Meta is used to change the behavior of the models such ordering, verbose_name etc. Though it is optional to be included in your models.