Thereissoupinmyfly
Thereissoupinmyfly

Reputation: 244

Django. Processing uploaded csv on the basis of user input

Please let me know if this is an inappropriate question. I feel it is a little broad.

I am fairly new to Django and coding an app for educational purposes. What I am trying to achieve is to allow users to upload a CSV and then populate a model by specifying that datatype that is in each column of the CSV. I’m fine with the first half (users can upload csv which are then processed into a PropertyQuery model but currently they would need to download a template CSV file and ensure they conform to it. I’d like them to be able to upload any CSV and then specify the column’s data.

I don’t need a step by step explanation on how to achieve this but after spending a fair chunk of time searching I could use a pointer.

I hope that my flowchart below explains it better.

Many thanks.

enter image description here

Upvotes: 1

Views: 503

Answers (1)

Thereissoupinmyfly
Thereissoupinmyfly

Reputation: 244

This was far too broad to answer but I'm posting the solution I'm currently implementing in case anyone else comes across this.

I have two models in the back end.

The first model has a JSONmodelfield (https://github.com/bradjasper/django-jsonfield) and four intfields to save the columns numbers for street address, suburb, state, postcode)

I will use jquery and papa parse(http://papaparse.com/) on a modelform to process the csv file clientside, save the json into the hidden JSONmodelfield and create dropdown selections from the csv headers the selection from each of these dropdowns is also passed to the hidden intfields. On save() the json is processed using the values in the intfields to populate a second model.

The second model just has 4 charfields for the street address, suburb, state, postcode

Upvotes: 1

Related Questions