Get model name from instance

How can I get a model name as a "string" from a model instance. I know you can do something like type(model_instance) but this is returning the class itself as an object <Model_Name: > not as a string.


from user.models import User
user = User.objects.create_user(tel='1234567890', password='YKH0000000')
print(user._meta.model)
<class 'user.models.User'>
print(user._meta.model.__name__)
User
print(user.__class__.__name__)
User

通过定义strunicode方法?

链接地址: http://www.djcxy.com/p/40954.html

上一篇: 获取类变量驻留在

下一篇: 从实例获取模型名称