api: do not fail on missing title

This commit is contained in:
Benjamin Dauvergne 2018-09-27 15:52:04 +02:00
parent 07e68ef209
commit bcd28f4722
1 changed files with 5 additions and 1 deletions

View File

@ -263,7 +263,11 @@ class AppConfig(django.apps.AppConfig):
del serializer.fields['last_login']
def get_gender(obj):
title = obj.attributes.title
attributes = obj.attributes
try:
title = attributes.title
except AttributeError:
return None
return {'Monsieur': 'male', 'Madame': 'female'}.get(title)
serializer.get_gender = get_gender