Processing uploaded csv on the basis of user input

2015-01-15 Thread David Mutton


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.




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5acdad9-eb00-438a-bf37-faf7a66a82a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Processing uploaded csv on the basis of user input

2015-01-15 Thread Jani Tiainen
Hi,

I do something similiar this way:


You could leverage Django (model)form to validate date and to normalize
it to proper data.

That way you would put design a contract between users that you state
which column names are matched to your internal data.

Then feed each row to (model)form if row is valid, you can save it, if
not you can log errors for showing them after import is done.

Another option is (what you're proposing) is to have such a dynamic
middle form to make mapping between columns frm csv and your model.
After that just map values from CSV to a dict, pass it to (model)form,
validate and save if valid.

As you see, Django (model)form is _very_ useful to validate user input
- even input is not directly from HTML form.

On Thu, 15 Jan 2015 18:54:13 -0800 (PST)
David Mutton  wrote:

> 
> 
> 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.
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> django-users+unsubscr...@googlegroups.com. To post to this group,
> send email to django-users@googlegroups.com. Visit this group at
> http://groups.google.com/group/django-users. To view this discussion
> on the web visit
> https://groups.google.com/d/msgid/django-users/c5acdad9-eb00-438a-bf37-faf7a66a82a5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 

Jani Tiainen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150116085438.0f3b4fec%40jns42-l.w2k.keypro.fi.
For more options, visit https://groups.google.com/d/optout.


Re: Processing uploaded csv on the basis of user input

2015-01-17 Thread David Mutton


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.







On Friday, 16 January 2015 13:24:13 UTC+10:30, David Mutton wrote:
>
> 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.
>
>
> 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a70ebcd-6696-4a25-8ceb-e0b5fcc71a80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.