Include DocumentProperties.data in Document.json()
This commit is contained in:
parent
a55cbcfb9f
commit
a8dcbbbe89
2 changed files with 7 additions and 3 deletions
|
@ -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:
|
||||
|
|
|
@ -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={})
|
||||
|
|
Loading…
Reference in a new issue