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