def build_evolutions():
 file = open('data/v1/evolutions.csv', 'rb')
 rdr = csv.reader(file, delimiter=',')
 method = [' ', 'level_up', 'trade', 'stone', 'other']
 for row in rdr:
  if (row[0] != 'id'):
   frm = Pokemon.objects.filter(pkdx_id=(int(row[1]) - 1))
   if (not frm.exists()):
    frm = Pokemon.objects.filter(pkdx_id=1)[0]
   else:
    frm = frm[0]
   to = Pokemon.objects.filter(pkdx_id=int(row[1]))
   if (not to.exists()):
    to = Pokemon.objects.filter(pkdx_id=2)[0]
   else:
    to = to[0]
   if (method[int(row[2])] == 'level_up'):
    e = Evolution(frm=frm, to=to, method=method[int(row[2])], level=(row[4] if (row[4] != '') else 0))
    e.save()
    print ('created link %s' % e.__unicode__())

def build_evolutions ( ) : file = open ( 'data/v1/evolutions.csv' , 'rb' ) rdr = csv . reader ( file , delimiter = ',' ) method = [ ' ' , 'level_up' , 'trade' , 'stone' , 'other' ] for row in rdr : if ( row [ 0 ] != 'id' ) : frm = Pokemon . objects . filter ( pkdx_id = ( int ( row [ 1 ] ) - 1 ) ) if ( not frm . exists ( ) ) : frm = Pokemon . objects . filter ( pkdx_id = 1 ) [ 0 ] else : frm = frm [ 0 ] to = Pokemon . objects . filter ( pkdx_id = int ( row [ 1 ] ) ) if ( not to . exists ( ) ) : to = Pokemon . objects . filter ( pkdx_id = 2 ) [ 0 ] else : to = to [ 0 ] if ( method [ int ( row [ 2 ] ) ] == 'level_up' ) : e = Evolution ( frm = frm , to = to , method = method [ int ( row [ 2 ] ) ] , level = ( row [ 4 ] if ( row [ 4 ] != '' ) else 0 ) ) e . save ( ) print ( 'created link %s' % e . __unicode__ ( ) )
build all the evolution links .