views:

414

answers:

2

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?

+2  A: 

I 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.

Jarret Hardie
I see your point regarding: FileField just storing the path of the local file. But in the your second paragraph, you said "... it will save the file path to the resume". What do you mean by that? And regarding blobs, ofcourse I dont want to do it that way. I just want to store the html content of every resume only in the db.
Maddy
+3  A: 

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.

Jiaaro
I think I am slowly arriving at the same conclusion
Maddy