Monday, October 3, 2011

Re: Import CSV to create multiple Models - Model Manager or in View?

A clean way would be to read in the CSV with csv.DictReader, and
ensure that the key names match your field names.

Then use a ModelForm for your model, and pass in each dict as the 'data' field.

This lets you re-use all the hard work already done in the ModelForm,
because the is_valid() method will validate your input, and the save()
method will create a new instance.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment