Right now, I have a Django application with an import feature which accepts a .zip
file, reads out the csv files and formats them to JSON and then inserts them into the database. The JSON file with all the data is put into temp_dir
and is called data.json
.
Unfortunatly, the insertion is done like so:
Building.objects.all().delete()
call_command('loaddata', os.path.join(temp_dir, 'data.json'))
My problem is that all the data is deleted then re-added. I need to instead find a way to update and add data and not delete the data.
I've been looking at other Django commands but I can't seem to find out that would allow me to insert the data and update/add records. I'm hoping that there is a easy way to do this without modifying a whole lot.