0

I'm new to Django and read many posts regarding file handling and uploading in Django.

I have a scenario in which a model field needs to be a file field. It needs to accept a JSON file (validate for other file formats) and extract the contents and assign the JSON string to the field. I don't need to store the file, redirect it to a view. Just extract and assign.

I need to design the field which has a text field and a file picker which picks the file and extracts the contents and assign it to the text field.

Any help with the code is appreciated.

Thanks!

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
Wizard
  • 21
  • 2
  • you can extract the content in the views , and assign that value to model textfield. for instance model_name.demo_textfield = demo_extracted_value – ancho Jan 08 '15 at 17:11
  • See http://stackoverflow.com/questions/5871730/need-a-minimal-django-file-upload-example for an easy to follow guide to setting up a file upload. Then you can follow what @ancho suggested and assign that JSON data to the model textfield. – alacy Jan 08 '15 at 17:18
  • Thanks, I'm just trying to understand. The link shows an upload, calling the view and saving it. Like I told I don't need to save the file but let the user choose the file, just read the contents and assign the value to the model field. And in the guide, the view is called directly from local host. In my case, I'm not calling a view. – Wizard Jan 08 '15 at 18:01
  • @Wizard well if you need a file picker to allow the user to choose a file don't you need a view? – alacy Jan 08 '15 at 19:36
  • I totally got your point. But this is in admin screen and a view needs to be associated with a URL and a request. Here there is no request response. – Wizard Jan 08 '15 at 21:17

0 Answers0