On 06.01-16:55, Victor Hooi wrote:
[ ... ]
> Valts, thanks for the reply - that looks interesting, and is similar
> in some ways to what I want - definitely going to check out the code.
> Basically, I just wanted a simple file-upload form, for the user to
> upload the two .CSV files. Then, there's quite a bit of processing to
> do on the two files, currently in a small python script.
> 
> My question was more along the lines of where should put all of the
> logic? Should it be in the model itself, somewhere, and the file-
> upload form just passes across the raw data from the .csv files? Where
> would the file-handling stuff go? Is it easier to do it via raw SQL,
> or via the django models? Any chance of sample code =)?

no chance of sample code but i would put the code in the upload
processing and simply instantiate objects with something like

        if request.method == 'POST' :
                while more_data() :
                        x = myModel()
                        ( x.a, x.b, x.c, x.n ) = read_tuple()
                        x.save()

obviously there's a lot more code required there but it should give
an idea of one simple way to populate the DB from posted data.  i
believe valts also suggested doing it in batches (i.e. don't 'save()'
every object) to improve the performance.

personally, i wouldn't even use django for this, i'd just import the
CSV into a database, perform my processing (i.e. eliminate duplicates,
tidy the data, etc) and migrate the validated data to the django system
for reporting or management or whatever.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to