tags:

views:

77

answers:

1

Dear all,

I'm trying to get my head around Django ORM. I've been reading django.db.models.base.py source code but still could understand how does the Model.objects attributes in our Model object gets defined. Does anybody know how does django adds that objects attribute into our Model object?

Thanks in advance

+3  A: 

The Django ORM makes heavy use of Python metaclasses. From Wikipedia:

In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances.

Here's a blog post that describes how metaclasses are used in the Django ORM: How the Heck do Django Models Work

piquadrat
Cool. Thanks for the link on Django ORM. :-)
jpartogi