Saturday, 1 October 2016

python - Why are django model classes not of type "type"?

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)

>>> class B(A): pass #checking type of child class
>>> type(B)


>>> from collections import OrderedDict #checking type of imported class
>>> type(OrderedDict)



Now look at this:



>>> from my_project.models import MyModel
>>> type(MyModel)




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?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...