5👍
✅
Passing an object to type()
will tell you the type of the object.
print type(some_model)
8👍
Test if some_model is of type inherited from MyType
issubclass(type(some_model), MyType)
Test if some_model is instance of MyType
isinstance(some_model, MyType)
👤Ilya
- [Django]-Passing context from child to parent template in Django
- [Django]-SIGWINCH ignored. Not daemonized
- [Django]-How to save django FileField to user folder?
- [Django]-Apache + Django on Windows does not start
- [Django]-How to serialize recursive relationship with self in Django REST Framework?
0👍
For if statements this worked for me
from app.models import SomeModel
model_var = SomeModel()
if type(model_var) == SomeModel:
#Do stuff
pass
- [Django]-Facebook Connect API error 191 with Django-socialregistration
- [Django]-Django template: How can I regroup a list of dictionaries by a nested property of each dictionary?
- [Django]-Django Serializer returns JSON for parent class objects only and leave child objects as same?
Source:stackexchange.com