I need to export data from one database into another database. The dataobject needs to be mapped to a dictionary.
each row needs to be saved twice with different values from a list foobar=['foo','bar'].
foobar=['foo','bar']
data = []
for q in queryset:
row = {"id": q.id,
"created_at": q.created_at}
for f in foobar:
row['index'] = f
data.append(row)
bulksave(data)
this doesn't give the desired result:
print data
[{'id': 1, 'created_at': '2017-01-01', 'index': 'bar'},
{'id': 2, 'created_at': '2017-01-02', 'index': 'bar'}]
Where the desired output would have 'foo' and 'bar' as the index. How do I get this to work? Taking a different approach would be to loop differently:
for f in foobar:
for q in queryset
this works, but takes twice the time because each element in the queryset will be evaluated twice.
print data? It should have 4 items, but confusingly its only two unique items with each repeated in the list.datashould have 4 unique entries.