[Fixed]-How to store files in djangos array field


Currently, I think the django.contrib.postgres.fields.ArrayField is in active development. The django.contrib package is new to django 1.8 (which is still in beta) so I think this functionality is too early to count on.

The text field you are seeing is meant to be a delimited string which is saved in the array. It kinda makes sense with an array of FileFields because the FileField saves a URL string and not a blob of the file (as far as I can tell).

A \d table gives the table information on that column as follows:

arrayexample=# \d example_post
Column      | Type                     | Modifiers
attachments | character varying(100)[] |

Currently the field you are seeing in admin is created from here. Notice it inherits from forms.CharField while a FileField uses forms.ClearableFileInput.

I don’t think the functionality you are looking for currently exists in Django but I think it is feasible to build it. Personally, I would approach building it by subclassing the existing ArrayField and overriding the formfield to use my custom form_class to better handle an Array of FileFields.

I hope this helps, I also don’t see any open pull requests for this feature.



You should use FileField.storage which handles the storage and retrieval of files. For more details, refer Django’s documentation on Managing Files

Leave a comment