Using "id" in data not "_id" as its a mapping of fieldnames (#255)

This commit is contained in:
Ross Lawley 2013-04-17 15:07:57 +00:00
parent b4d87d9128
commit dcf3c86dce
3 changed files with 16 additions and 15 deletions

View File

@ -10,7 +10,7 @@ Changes in 0.7.10
- Added Django sessions TTL support (#224)
- Fixed issue with numerical keys in MapField(EmbeddedDocumentField()) (#240)
- Fixed clearing _changed_fields for complex nested embedded documents (#237, #239, #242)
- Added "_id" to _data dictionary (#255)
- Added "id" back to _data dictionary (#255)
- Only mark a field as changed if the value has changed (#258)
- Explicitly check for Document instances when dereferencing (#261)
- Fixed order_by chaining issue (#265)

View File

@ -192,7 +192,7 @@ class BaseField(object):
return self
# Get value from document instance if available, if not use default
value = instance._data.get(self.name or self.db_field)
value = instance._data.get(self.name)
if value is None:
value = self.default
@ -207,9 +207,9 @@ class BaseField(object):
"""
changed = False
if (self.name not in instance._data or
instance._data[self.name or self.db_field] != value):
instance._data[self.name] != value):
changed = True
instance._data[self.name or self.db_field] = value
instance._data[self.name] = value
if changed and instance._initialised:
instance._mark_as_changed(self.name)
@ -825,6 +825,7 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
if not new_class._meta.get('id_field'):
new_class._meta['id_field'] = 'id'
new_class._fields['id'] = ObjectIdField(db_field='_id')
new_class._fields['id'].name = 'id'
new_class.id = new_class._fields['id']
# Merge in exceptions with parent hierarchy

View File

@ -1553,8 +1553,8 @@ class DocumentTest(unittest.TestCase):
self.assertEqual(2, len(keys))
self.assertTrue('e' in keys)
# Ensure that the _id field has the right id
self.assertTrue('_id' in keys)
self.assertEqual(doc._data.get('_id'), doc.id)
self.assertTrue('id' in keys)
self.assertEqual(doc._data.get('id'), doc.id)
def test_save(self):
"""Ensure that a document may be saved in the database.
@ -3402,8 +3402,8 @@ class DocumentTest(unittest.TestCase):
Person(name="Harry Potter").save()
person = Person.objects.first()
self.assertTrue('_id' in person._data.keys())
self.assertEqual(person._data.get('_id'), person.id)
self.assertTrue('id' in person._data.keys())
self.assertEqual(person._data.get('id'), person.id)
def test_complex_nesting_document_and_embedded_document(self):