1

I'm looking to create a ModelForm field that accepts comma separated values and stores values as rows in the database (as a many to one relationship to another object)

I've tried searching for something like this but had no luck. I'm thinking of doing it manually via a normal Form but before I do, I'd like to hear suggestions. Is there a simple method of doing this? Custom widget? Custom field? Both?

RS7
  • 2,341
  • 8
  • 34
  • 57
  • do you mean the user uploads a .csv, or they input it as delimited text, if the latter why? will it be just one record per 'entry'? – T I Jun 27 '12 at 22:20
  • @TomIngram - I'm thinking/hoping a textarea with delimited text would provide a smoother experience than the modelformset I have in place at the moment (requires a button click on every new value). It'd be a new row for every record, so `'apple, orange, pear'` would turn into the three rows `apple`, `orange` and `pear`. – RS7 Jun 27 '12 at 22:33
  • by the sounds of it you'd need a modelform that parses the string and relates it to a model, also i would look at a [manager](http://stackoverflow.com/questions/2655670/how-do-i-perform-a-batch-insert-in-django) for batch inserts, sorry i'm not going to be much help on this. – T I Jun 28 '12 at 09:30

0 Answers0