(De)serializers for tag fields
This commit is contained in:
parent
73e41d568e
commit
72b4c150f6
4 changed files with 44 additions and 54 deletions
|
@ -145,3 +145,23 @@ def resolve_foreign_key(model, remote_id):
|
|||
'Could not resolve remote_id in %s model: %s' % \
|
||||
(model.__name__, remote_id))
|
||||
return result
|
||||
|
||||
|
||||
def tag_formatter(tags):
|
||||
''' helper function to extract foreign keys from tag activity json '''
|
||||
items = []
|
||||
types = {
|
||||
'Book': models.Book,
|
||||
'Mention': models.User,
|
||||
}
|
||||
for tag in tags:
|
||||
tag_type = tag.get('type')
|
||||
if not tag_type in types:
|
||||
continue
|
||||
remote_id = tag.get('href')
|
||||
try:
|
||||
item = resolve_foreign_key(types[tag_type], remote_id)
|
||||
except ActivitySerializerError:
|
||||
continue
|
||||
items.append(item)
|
||||
return items
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue