#!/usr/bin/python # -*- coding:utf-8 -*- from tcmdb.models import * fr = open('/home/ruichao/djcode/tcm/database/protein_protein.txt','r') for line in fr: line = line[:-1] (protein1, proteins) = line.split('\t') protein_list = proteins.split(',') try: target1 = Target.objects.get(first_access=protein1) for protein in protein_list: try: target = Target.objects.get(first_access=protein) target1.proteins.add(target) target1.save() except Target.DoesNotExist: print(protein1 + ' is not in the database') except Target.DoesNotExist: print(protein1 + ' is not in the database')