views:

114

answers:

3

Can someone please explain why is meta class used in the following example.

Ex:

Class Employee (models.Model):
   name = models.ForeignKey(name)
   Gender = models.IntegerField()


   class Meta:
     ordering = ["Gender"]

Thanks...

+4  A: 

Django models use the Meta class to contain extra information about the model that would not necessarily be appropriate to contain within the model class itself. Note that this is not the same as Python's metaclass; that is a completely different topic.

Ignacio Vazquez-Abrams
A: 

Because author/programmer wants to sort results by value of Gender field.

bluszcz
+1  A: 

In this case it defines the default field for ordering if you don't provide ORDER_BY in your query.

Felix Kling