expand connections
This commit is contained in:
parent
b4f1b59718
commit
9626995fd4
2 changed files with 22 additions and 1 deletions
|
|
@ -256,6 +256,18 @@ class Item(models.Model):
|
|||
self.external_data = data
|
||||
self.save()
|
||||
|
||||
def expand_connections(self):
|
||||
c = self.get('connections')
|
||||
connections = {}
|
||||
if c:
|
||||
for t in c:
|
||||
connections[t] = [{'item': l.itemId, 'title': l.get('title')}
|
||||
for l in Item.objects.filter(itemId__in=c[t])]
|
||||
connections[t].sort(key=lambda a: c[t].index(a['item']))
|
||||
if not connections[t]:
|
||||
del connections[t]
|
||||
return connections
|
||||
|
||||
def __unicode__(self):
|
||||
year = self.get('year')
|
||||
if year:
|
||||
|
|
@ -441,6 +453,9 @@ class Item(models.Model):
|
|||
if 'cast' in i and isinstance(i['cast'][0], list):
|
||||
i['cast'] = map(lambda x: {'actor': x[0], 'character': x[1]}, i['cast'])
|
||||
|
||||
if 'connections' in i:
|
||||
i['connections'] = self.expand_connections()
|
||||
|
||||
if not keys or 'posterRatio' in keys:
|
||||
i['posterRatio'] = self.poster_width / self.poster_height
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue