I have a django form where I have a FileField which accepts user's resume. I am gonna convert the resume to a html document LATER. So I thought of pickling the original document right away and store in it a db colum and later unpickle it and convert it. Is that possible?
views:
414answers:
2I don't think you'd need to resort to pickling the FileField instance. All FileField stores is the path on the drive where the file has been saved... in that sense, the file is already stored for later consumption, and pickling the field instance won't really get you much. In fact, since the field doesn't actually store the data, pickling it won't really do anything :-) See the django docs on FileField.
When your model with the FileField is saved, it will save the file path to the resume. Any process which later comes along can load the resume from the drive, convert it to HTML, and then either delete the original resume, or do whatever other "cleanup" processing you like.
If you need to store the actual file contents in the database, you would be looking at creating a Blob field for your model instead... blobs are DB-specific. This question on SO has a bare-bones implementation. Note, though, that many people feel storing binary in the DB is a poor-performing idea, and indeed you should be careful about structuring your app that way. This google django-developers forum post has some good discussion and sample code on Django and blobs.
it will be much better idea to just store the file and then open it again when you want to convert it. Pickling it and storing in the database will be a pretty big hit on your performance. Especially if the files are large.