Skip to content

Commit 747e0e9

Browse files
committed
Implement MutableMapping in DocumentMetaWrapper
Meta is optional (for EmbeddedDocuments) in MongoEngine 0.7.x and requires more of dict's raw functionality.
1 parent 1c138c0 commit 747e0e9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

mongodbforms/documentoptions.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from collections import MutableMapping
23

34
from django.db.models.fields import FieldDoesNotExist
45
from django.db.models.options import get_verbose_name
@@ -20,7 +21,7 @@ def __setattr__(self, attr, value):
2021
setattr(self.obj, attr, value)
2122
super(PkWrapper, self).__setattr__(attr, value)
2223

23-
class DocumentMetaWrapper(object):
24+
class DocumentMetaWrapper(MutableMapping):
2425
"""
2526
Used to store mongoengine's _meta dict to make the document admin
2627
as compatible as possible to django's meta class on models.
@@ -41,7 +42,7 @@ class DocumentMetaWrapper(object):
4142

4243
def __init__(self, document):
4344
self.document = document
44-
self._meta = document._meta
45+
self._meta = getattr(document, '_meta', {})
4546

4647
try:
4748
self.object_name = self.document.__name__
@@ -191,6 +192,21 @@ def __setattr__(self, name, value):
191192
def __getitem__(self, key):
192193
return self._meta[key]
193194

195+
def __setitem__(self, key, value):
196+
self._meta[key] = value
197+
198+
def __delitem__(self, key):
199+
return self._meta.__delitem__(key)
200+
201+
def __contains__(self, key):
202+
return key in self._meta
203+
204+
def __iter__(self):
205+
return self._meta.__iter__()
206+
207+
def __len__(self):
208+
return self._meta.__len__()
209+
194210
def get(self, key, default=None):
195211
try:
196212
return self.__getitem__(key)

0 commit comments

Comments
 (0)