<s> from django . utils . encoding import smart_text <EOL> from django . db . models import Q , Manager , Model <EOL> from django . core . exceptions import MultipleObjectsReturned , ObjectDoesNotExist <EOL> class PersonManager ( Manager ) : <EOL> def get_by_name ( self , name , create = False ) : <EOL> name = smart_text ( name ) <EOL> persons = self . filter ( ( Q ( aliases__name__in = name ) | Q ( name = name ) ) ) <EOL> if persons : <EOL> return persons [ <NUM_LIT:0> ] <EOL> else : <EOL> if create : <EOL> return self . create ( name = name ) <EOL> return None </s>
