get entity by name
This commit is contained in:
parent
8c9b92479d
commit
d52dc11b4c
2 changed files with 11 additions and 3 deletions
|
@ -226,9 +226,9 @@ class Annotation(models.Model):
|
||||||
j['languages'] = self.languages.split(',')
|
j['languages'] = self.languages.split(',')
|
||||||
l = self.get_layer()
|
l = self.get_layer()
|
||||||
if l['type'] == 'entity':
|
if l['type'] == 'entity':
|
||||||
qs = Entity.objects.filter(id=ox.fromAZ(self.value))
|
entity = Entity.get_by_name(self.value)
|
||||||
if qs.count() > 0:
|
if entity > 0:
|
||||||
j['entity'] = qs[0].json(user=user)
|
j['entity'] = entity.json(user=user)
|
||||||
else:
|
else:
|
||||||
j['entity'] = {}
|
j['entity'] = {}
|
||||||
elif l['type'] == 'event':
|
elif l['type'] == 'event':
|
||||||
|
|
|
@ -54,6 +54,14 @@ class Entity(models.Model):
|
||||||
def get(cls, id):
|
def get(cls, id):
|
||||||
return cls.objects.get(pk=ox.fromAZ(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
|
@classmethod
|
||||||
def get_or_create(model, name):
|
def get_or_create(model, name):
|
||||||
qs = model.objects.filter(name_find__icontains=u'|%s|'%name)
|
qs = model.objects.filter(name_find__icontains=u'|%s|'%name)
|
||||||
|
|
Loading…
Reference in a new issue