Allow args and kwargs to be passed through to_json (#420)

This commit is contained in:
Ross Lawley 2013-07-29 15:29:48 +00:00
parent a458d5a176
commit 67f43b2aad
3 changed files with 8 additions and 4 deletions

View File

@ -2,6 +2,10 @@
Changelog
=========
Changes in 0.8.4
================
- Allow args and kwargs to be passed through to_json (#420)
Changes in 0.8.3
================
- Fixed EmbeddedDocuments with `id` also storing `_id` (#402)

View File

@ -321,9 +321,9 @@ class BaseDocument(object):
message = "ValidationError (%s:%s) " % (self._class_name, pk)
raise ValidationError(message, errors=errors)
def to_json(self):
def to_json(self, *args, **kwargs):
"""Converts a document to JSON"""
return json_util.dumps(self.to_mongo())
return json_util.dumps(self.to_mongo(), *args, **kwargs)
@classmethod
def from_json(cls, json_data):

View File

@ -827,9 +827,9 @@ class BaseQuerySet(object):
# JSON Helpers
def to_json(self):
def to_json(self, *args, **kwargs):
"""Converts a queryset to JSON"""
return json_util.dumps(self.as_pymongo())
return json_util.dumps(self.as_pymongo(), *args, **kwargs)
def from_json(self, json_data):
"""Converts json data to unsaved objects"""