'How do I automatically upload an automatically created file to a FileField in django? (or equivalent functionality)

I have a method that creates a csv file from a serialized model and writes the file to a data folder. This works - the csv is created, but to do anything with it a user has to manually upload it back in to the app, which is awkward.

I'd like to automate the step of uploading that same file to the UploadFile model in another app within the same project - that is, when it is created, instead of, or in addition to, being written to the file tree, the file is uploaded and stored in a FileField (or location anyway) in an UploadedFile.

EDIT: In this app - a user fills out several forms which, taken together, create a Group. The Group model has a many-2-many relationship to a People model, which has many-2-many relationships to the Attribute and Stats models. Each model has an associated form.

So a user would create a Group, submit it which writes it to the data folder, and then -<(magic happens)>- the Group.name, Group.label, and Group.data are applied to the UploadFileForm which uploads it to the UploadFile model.

I have searched google for something like this and found nothing -- which makes me think I am forming the question incorrectly. Any help is appreciated.

I'll post my code if need be, but a general solution would be helpful enough.

EDIT: I realize now that I can't use 'initial' to populate a FileField in a django mode -- security risk. Since that won't work - I'm out of ideas for how to upload the last file created to a FileField in a django model by any means.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source