1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from ebook.models import Subject from django.db import connection f = open('subjects.txt') for line in f: name=line.strip() if not name: continue try: Subject.objects.get(name__iexact=name) continue except Subject.DoesNotExist: pass s=Subject() s.name=name s.save() connection.close() |