Where we store pickles in the database, we use a TextField, then compress and base64-encode the data:
class BlobbyRecord(models.Model): blob = modelsTextField() ... bin = pickle.dumps(my_data, 0) blobby = BlobbyRecord(blob=zlib.compress(bin).encode('base64')) blobby.save() Reading is just the opposite: blobby = BlobbyRecord.objects.get(blah blah) bin = zlib.decompress(blobby.blob.decode('base64')) my_data = pickle.loads(bin) If you have binary data other than pickles to store, just leave out the first line in the first snippet, and the last in the last. --Ned. http://nedbatchelder.com/blog shabda wrote: > Yes I was looking for snippets and recipes, not storing them in DB. > There are some instances when storing things in DB is just too > convinient comaring to storing them on files. For example I get some > JSON from a external web service call. I want to cache it in the > system, so I want to just pickle it and dump it i the db. Blob would > be very nice here. > > On Mar 28, 10:48 am, "Rishabh Manocha" <[EMAIL PROTECTED]> wrote: > >> I think he meant recipes in that are there any recipes to accomplish >> this (storing binary data to the DB). Unless I'm getting this >> completely wrong, he was not talking about cooking recipes :). >> >> I would be interested in a solution for this too. There are cases >> where apps running as the apache/web user do not have write >> permissions to the local FS (an example would be the sourceforge >> servers). In these situations, having your db store this information >> is the only way to go. >> >> Best, >> >> R >> >> On Fri, Mar 28, 2008 at 7:45 AM, Dan Ellis <[EMAIL PROTECTED]> wrote: >> >> >>> On Mar 27, 9:05 pm, Mike H <[EMAIL PROTECTED]> wrote: >>> >>> > Reading large >>> > chunks of file data from a db just wastes db resources >>> >>> A recipe is unlikely to be a large chunk of file data. Pictures of >>> food, sure, don't store those in the DB. Storing the text in the DB >>> also means you can make use of its full text searching capability. >>> > > > > -- Ned Batchelder, http://nedbatchelder.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---