我想查看与我得到的 SimplyLazyObject 对应的模型实例,以便我可以打印它的__dict__
. 如何找到模型实例?
e.g.,
ipdb> user
<django.utils.functional.SimpleLazyObject object at 0x10c84d150>
我想查看与我得到的 SimplyLazyObject 对应的模型实例,以便我可以打印它的__dict__
. 如何找到模型实例?
e.g.,
ipdb> user
<django.utils.functional.SimpleLazyObject object at 0x10c84d150>
SimplyLazyObject 实例的_wrapped
属性包含模型实例。
例如,
ipdb> user
<django.utils.functional.SimpleLazyObject object at 0x10c84d150>
ipdb> pp(user.__dict__)
{'_setupfunc': <function <lambda> at 0x10c846938>,
'_wrapped': <User: foo@bednark.com>}
ipdb> user._wrapped
<User: foo@bednark.com>
ipdb> type(user._wrapped)
<class 'django.contrib.auth.models.User'>
ipdb> pp(user._wrapped.__dict__)
{'_profile_cache': <UserProfile: foo@bednark.com>,
'_state': <django.db.models.base.ModelState object at 0x10c869290>,
'_username': u'4qInglEqb3HzIFMEuo1H4WkR-HXbWI',
'date_joined': datetime.datetime(2013, 7, 29, 0, 53, 5, 545109),
'email': u'foo@bednark.com',
'first_name': u'Rob',
'id': 24,
'is_active': True,
'is_staff': False,
'is_superuser': False,
'last_login': datetime.datetime(2013, 7, 29, 0, 53, 23, 739774),
'last_name': u'Bednark',
'password': u'pbkdf2_sha256$10000$a1pAQhQuJ2Ng$79CDBtDYWsBxnxShXUSPOTNUVj63cDpaocay6BNzfRs=',
'username': u'foo@bednark.com'}