On Tue, Apr 23, 2013 at 10:37 AM, Derek <gamesb...@gmail.com> wrote:

>
> Yes, this is what I did; it is a significant amount of work to create such
> a facility and I would have been glad if someone had done this already!
>
> Of course, linking fields to column headers is the very simple part of it
> - you still need to load rows of data items; validate each-and-every item
> of data (including those which are - or may be or should be -  linked to
> fields in other tables); allow for data conversions decide what to do with
> duplicates; figure out error reporting (by field?  by row?  by sheet?);
> allow for re-uploads; and so on and so on.
>
> CSV Import is very slippery slope for your application - my advice is to
> avoid if at all possible!!
>
>
In my experience, CSV is wonderful, and any imports of any kind you do for
Django models should make use of a ModelForm 100% of the time.

CSV file -> csv.DictReader -> ModelForm -> is_valid() -> save()

For fields that are foreign keys you will obviously have to read through
the dictionaries created by DictReader and have simple functions that does
the lookup of the appropriate foreign keys, but that's no big deal.

Using a ModelForm makes sure your data is clean, and any validation you do
outside of that is either a completely wasted effort (duplicates ModelForm
clean()) or something that should be in your custom ModelForm subclass.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to