diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index ec903fa5..64bf7455 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -226,9 +226,9 @@ class Annotation(models.Model): j['languages'] = self.languages.split(',') l = self.get_layer() if l['type'] == 'entity': - qs = Entity.objects.filter(id=ox.fromAZ(self.value)) - if qs.count() > 0: - j['entity'] = qs[0].json(user=user) + entity = Entity.get_by_name(self.value) + if entity > 0: + j['entity'] = entity.json(user=user) else: j['entity'] = {} elif l['type'] == 'event': diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 74ae5ac0..f49768e1 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -54,6 +54,14 @@ class Entity(models.Model): def get(cls, id): return cls.objects.get(pk=ox.fromAZ(id)) + @classmethod + def get_by_name(cls, name, default=None): + qs = cls.objects.filter(name_find__icontains=u'|%s|'%name) + if qs.count(): + return qs[0] + else: + return default + @classmethod def get_or_create(model, name): qs = model.objects.filter(name_find__icontains=u'|%s|'%name)