[Answer]-Where is the model instance for a Django SimplyLazyObject instance?

1👍

The _wrapped attribute of the SimplyLazyObject instance contains the model instance.

e.g.,

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

Leave a comment