Include DocumentProperties.data in Document.json()

This commit is contained in:
Will Thompson 2016-02-19 10:59:15 +00:00 committed by j
parent a55cbcfb9f
commit a8dcbbbe89
2 changed files with 7 additions and 3 deletions

View file

@ -165,8 +165,12 @@ class Document(models.Model):
elif key == 'user': elif key == 'user':
response[key] = self.user.username response[key] = self.user.username
elif key == 'entities': elif key == 'entities':
response[key] = [e.json(['id', 'type', 'name']) dps = self.documentproperties.select_related('entity').order_by('index')
for e in self.entities.all().order_by('documentproperties__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)): elif hasattr(self, _map.get(key, key)):
response[key] = getattr(self, _map.get(key,key)) or '' response[key] = getattr(self, _map.get(key,key)) or ''
if item: if item:

View file

@ -258,7 +258,7 @@ class DocumentProperties(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=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') entity = models.ForeignKey(Entity, related_name='documentproperties')
index = models.IntegerField(default=0) index = models.IntegerField(default=0)
data = fields.DictField(default={}) data = fields.DictField(default={})