from mtgweb.lib.mtg import database from mtgweb.analyzer.models import Card, CardType, Attribute def doimport(): db = database.TextDB('lib/mtg/db.txt') for c in db.findCard(): print c try: card_type = CardType.objects.get(name=c.type) except: card_type = CardType.objects.create(name=c.type) card = Card(name=c.name, type=card_type,cost=c.cost, power=c.power, toughness=c.toughness) card.converted_cost = c.cost.converted() card.text = "\n".join(c.text) card.save() attributes = [] for a in c.attributes: try: attr = Attribute.objects.get(name=a) except: attr = Attribute.objects.create(name=a) card.attributes.add(attr) doimport()