Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/aparo/mongodj
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Apr 22, 2010
2 parents c36fa51 + bb4cfb6 commit 0730417
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 249 deletions.
7 changes: 5 additions & 2 deletions mongodj/fields.py
Expand Up @@ -12,19 +12,22 @@ class EmbeddedModel(models.Model):
_embedded_in =None

def save(self, *args, **kwargs):
if self.pk is None:
self.pk = ObjectId()
if self._embedded_in is None:
raise RuntimeError("Invalid save")
self._embedded_in.save()

def serialize(self):
if self.pk is None:
self.pk = ObjectId()
result = {'_app':self._meta.app_label,
'_model':self._meta.module_name,
'pk':self.pk}
'_id':self.pk}
for field in self._meta.fields:
result[field.attname] = getattr(self, field.attname)
return result


class ListField(Field):
"""A list field that wraps a standard field, allowing multiple instances
of the field to be used as a list in the database.
Expand Down
4 changes: 4 additions & 0 deletions mongodj/mongodb_serializer.py
Expand Up @@ -23,6 +23,7 @@ def decode_django(data):
del data['_type']
del data['_app']
del data['_model']
data.pop('_id', None)
data = dict([(str(k),v) for k,v in data.items()])
return model.model_class()(**data)

Expand All @@ -46,6 +47,9 @@ def transform_incoming(self, son, collection):

def transform_outgoing(self, son, collection):
if isinstance(son, dict):
if "_id" in son:
pk = son.pop('_id')
son['id'] = unicode(pk)
if "_type" in son and son["_type"] in [u"django", u'emb']:
son = decode_django(son)
else:
Expand Down

0 comments on commit 0730417

Please sign in to comment.