Django SimplyLazyObject实例的模型实例在哪里?

时间:2013-07-29 08:35:13

标签: django debugging django-models

我希望看到与我正在获得的SimplyLazyObject相对应的模型实例,以便我可以打印它__dict__。如何找到模型实例?

e.g.,
ipdb> user
<django.utils.functional.SimpleLazyObject object at 0x10c84d150>

1 个答案:

答案 0 :(得分:1)

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'}