Hello everybody,
I've fallen in love with Django two years ago and I've been using it for my job projects. In the past I found very useful information in this group, so a big thank you guys!
I have a little doubt.
I have to import in Django db (sqlite for local development, mySql on the server) about 1.000.000 xml documents.
The model class is the following:
class Doc(models.Model):
doc_code = models.CharField(max_length=20, unique=True, primary_key=True, db_index = True)
doc_text = models.TextField(null=True, blank=True)
related_doc= models.ManyToManyField('self', null=True, blank=True, db_index = True)
From what I know bulk insertion is not possibile because I have a ManyToManyField relation.
So I have this simple loop (in pseudo code)
for each xml:
extract from the xml date-> mydoc_code, mydoc_text, myRelated_doc_codes
myDoc = Doc.object.get_or_create(doc_code = mydoc_code)[0]
myDoc.doc_text = mydoc_text
for reldoc_code in myRelated_doc_codes:
myRelDoc = Doc.object.get_or_create(doc_code = reldoc_code )[0]
myDoc.related_doc.add(myRelDoc )
myDoc.save()
I'm doing it right? Do you have some suggestions, recommendation? I fear that since I have 1.000.000 docs to import, it will take a loooot of time, especially during the get_or_create routines
thank you in advance everybody!
John