10

Open a python shell on your django project root with python manage.py shell and observe the following:

>>> class A(object): pass #checking type of user-defined class
...
>>> type(A)
<type 'type'>
>>> class B(A): pass #checking type of child class
>>> type(B)
<type 'type'>
>>> from collections import OrderedDict #checking type of imported class
>>> type(OrderedDict)
<type 'type'>

Now look at this:

>>> from my_project.models import MyModel
>>> type(MyModel)
<class 'django.db.models.base.ModelClass'>

Can somebody explain what is going on here? Django models are clearly defined as classes in models.py:

class MyModel(models.Model):
  pass

So why are they not of type "type" when they are imported? Does Django change the model class type through some black magick, or am I just missing something obvious?

galarant
  • 1,959
  • 19
  • 24

0 Answers0