I'm building an application with python and Django. I have several models but I need to get data from one model to another (the relation can be made with a SOSS (sales order number). I do have the logic to do that, but is not as efficient as I would wanted. It takes around 5-6 min to process the data.
My Model 1 has the relation number (po_number) and is related to Model 2 (there is called planning_number) It takes a lot of time because Model 2 has around 93,000 data lines.
This is my logic:
def import_withtimes(request):
print "importando With Times a ots report"
po_cache = list()
for item in Model1.objects.all():
if item.po_number in po_cache:
continue
withtimes = Model2.objects.filter(planning_order=item.po_number)
for wi in withtimes:
po_cache.append(wi.planning_order)
item.wms = wi.wms_order
item.status = wi.shipment_status
item.aging = wi.status_date
item.carrier = wi.service_level
item.add_date = wi.order_add_date
item.asn_validation = wi.asn_sent_time
item.docs_add_date = wi.docs_received_time
item.save()
My question is: Is there any way more efficient to reflect data from one model to another?