get entity by name
This commit is contained in:
parent
8c9b92479d
commit
d52dc11b4c
2 changed files with 11 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue