Adding handler to to_json calls on all serialized models.

This commit is contained in:
Samuel Clay 2011-12-25 12:45:07 -08:00
parent 6e1ebce64a
commit bd87f3484b
2 changed files with 10 additions and 1 deletions

View file

@ -1265,6 +1265,13 @@ class DuplicateFeed(models.Model):
def __unicode__(self):
return "%s: %s" % (self.feed, self.duplicate_address)
def to_json(self):
return {
'duplicate_address': self.duplicate_address,
'duplicate_feed_id': self.duplicate_feed_id,
'feed_id': self.feed.pk
}
def merge_feeds(original_feed_id, duplicate_feed_id, force=False):
from apps.reader.models import UserSubscription

View file

@ -43,7 +43,9 @@ def json_encode(data, *args, **kwargs):
# Opps, we used to check if it is of type list, but that fails
# i.e. in the case of django.newforms.utils.ErrorList, which extends
# the type "list". Oh man, that was a dumb mistake!
if isinstance(data, list):
if hasattr(data, 'to_json'):
ret = data.to_json()
elif isinstance(data, list):
ret = _list(data)
# Same as for lists above.
elif isinstance(data, dict):