diff --git a/django/utils/functional.py b/django/utils/functional.py
index 1b5200c..bf850db 100644
a
|
b
|
class LazyObject(object):
|
230 | 230 | self._setup() |
231 | 231 | delattr(self._wrapped, name) |
232 | 232 | |
| 233 | def __getitem__(self, name): |
| 234 | if self._wrapped is empty: |
| 235 | self._setup() |
| 236 | return self._wrapped[name] |
| 237 | |
| 238 | def __setitem__(self, name, val): |
| 239 | if self._wrapped is empty: |
| 240 | self._setup() |
| 241 | self._wrapped[name] = val |
| 242 | |
233 | 243 | def _setup(self): |
234 | 244 | """ |
235 | 245 | Must be implemented by subclasses to initialise the wrapped object. |
diff --git a/tests/regressiontests/utils/simplelazyobject.py b/tests/regressiontests/utils/simplelazyobject.py
index 3f81e8f..0c15cae 100644
a
|
b
|
from django.utils.functional import SimpleLazyObject, empty
|
10 | 10 | |
11 | 11 | |
12 | 12 | class _ComplexObject(object): |
| 13 | |
13 | 14 | def __init__(self, name): |
14 | 15 | self.name = name |
15 | 16 | |
… |
… |
class TestUtilsSimpleLazyObject(TestCase):
|
121 | 122 | self.assertEqual(unpickled, x) |
122 | 123 | self.assertEqual(six.text_type(unpickled), six.text_type(x)) |
123 | 124 | self.assertEqual(unpickled.name, x.name) |
| 125 | |
| 126 | def test_lazy_dict(self): |
| 127 | lazydict = SimpleLazyObject(lambda: {'one': 1, 'two': 2, |
| 128 | 'three': 3, 'four': 4}) |
| 129 | self.assertTrue(lazydict['one']) |
| 130 | lazydict['one'] = 0 |
| 131 | self.assertFalse(lazydict['one']) |