def get_or_create_person(name): qs = Person.objects.filter(name=name) if qs.count() > 0: return qs[0] else: new_person = Person() new_person.name = name new_person.save() return new_person
def create(self,validated_data): name = validated_data.pop('name') qs = Person.objects.filter(name=name) if qs.count() > 0: return qs[0] else: new_person = Person() new_person.name = name new_person.save() print('created person with name %s'%name) return new_person
def create(self, validated_data): name = validated_data.pop('name') qs = Person.objects.filter(name=name) if qs.count() > 0: return qs[0] else: new_person = Person() new_person.name = name new_person.save() logger.info('created person {}' % new_person.id) return new_person
def update(self, instance, validated_data): name = validated_data.pop('person')['name'] p = Person.objects.filter(name=name) if p.count() > 0: instance.person = p[0] else: p = Person() p.name = name p.save() instance.person = p print('created person with name %s' % name) if instance.person.name == 'unknown': instance.person_label_is_inferred = None else: instance.person_label_is_inferred = False print('updated label for face %d to %s' % (instance.id, instance.person.name)) instance.save() return instance
def update(self, instance, validated_data): name = validated_data.pop('person')['name'] p = Person.objects.filter(name=name) if p.count() > 0: instance.person = p[0] else: p = Person() p.name = name p.save() instance.person = p print('created person with name %s'%name) if instance.person.name == 'unknown': instance.person_label_is_inferred = None instance.person_label_probability = 0. else: instance.person_label_is_inferred = False instance.person_label_probability = 1. print('updated label for face %d to %s'%(instance.id, instance.person.name)) instance.save() return instance
def update(self, instance, validated_data): name = validated_data.pop('person')['name'] p = Person.objects.filter(name=name) if p.count() > 0: instance.person = p[0] else: p = Person() p.name = name p.save() instance.person = p logger.info('created person with name %s' % name) if instance.person.name == 'unknown': instance.person_label_is_inferred = None instance.person_label_probability = 0. else: instance.person_label_is_inferred = False instance.person_label_probability = 1. logger.info('updated label for face %d to %s' % (instance.id, instance.person.name)) cache.clear() instance.save() return instance