From a8dcbbbe890abf60ecd34df1833e7828f1499772 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 19 Feb 2016 10:59:15 +0000 Subject: [PATCH] Include DocumentProperties.data in Document.json() --- pandora/document/models.py | 8 ++++++-- pandora/entity/models.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pandora/document/models.py b/pandora/document/models.py index 69c9df17..5527f50a 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -165,8 +165,12 @@ class Document(models.Model): elif key == 'user': response[key] = self.user.username elif key == 'entities': - response[key] = [e.json(['id', 'type', 'name']) - for e in self.entities.all().order_by('documentproperties__index')] + dps = self.documentproperties.select_related('entity').order_by('index') + response[key] = entity_jsons = [] + for dp in dps: + entity_json = dp.entity.json(['id', 'type', 'name']) + entity_json['data'] = dp.data + entity_jsons.append(entity_json) elif hasattr(self, _map.get(key, key)): response[key] = getattr(self, _map.get(key,key)) or '' if item: diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 08114db2..faff0e25 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -258,7 +258,7 @@ class DocumentProperties(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) - document = models.ForeignKey(Document) + document = models.ForeignKey(Document, related_name='documentproperties') entity = models.ForeignKey(Entity, related_name='documentproperties') index = models.IntegerField(default=0) data = fields.DictField(default={})