Fix Python – How does Django’s nested Meta class work?


Asked By – miki725

I am using Django which allows people to add extra parameters to a class by using class Meta.

class FooModel(models.Model):
    class Meta:

The only thing I found in Python’s documentation was:

class FooMetaClass(type):

class FooClass:
    __metaclass__ = FooMetaClass

However, I don’t think this is the same thing.

Now we will see solution for issue: How does Django’s nested Meta class work?


You are asking a question about two different things:

  1. Meta inner class in Django models:

    This is just a class container with some options (metadata) attached to the model. It defines such things as available permissions, associated database table name, whether the model is abstract or not, singular and plural versions of the name etc.

    Short explanation is here: Django docs: Models: Meta options

    List of available meta options is here: Django docs: Model Meta options

    For latest version of Django: Django docs: Model Meta options

  2. Metaclass in Python:

    The best description is here: What are metaclasses in Python?

This question is answered By – Tadeck

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0