Monday, October 3, 2011

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

heya,

I'm coding up a Django form which will let the user upload a CSV file, then create and save multiple Model instances for each row in the CSV file.

At the moment, I'm trying to decide where to put the code that parses the CSV file and creates/saves the models.

I don't think it'd be an instance method on the Model itself, since that's for working on individual instances, and you'd need to pass a valid instance to the method.

Would it go in a custom Model Manager? Or should I have this logic in the View itself?

Also, I need to figure out a good way of passing ValidationErrors from the model.save() and passing them back to the view to display the user.

What would be a good way of hooking that up?

Cheers,
Victor

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/CiJuzj-Sh3wJ.
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