Django-picklefield v.0.2.1


**django-picklefield** provides an implementation of a pickled object field.Such fields can contain any picklable objects.The implementation is taken and adopted from `Django snippet #1694`_ by Taavi Taijala, which is inturn based on `Django snippet #513 `_by Oliver Beattie.django-picklefield is available under the MIT license.First of all, you need to have **django-picklefield** installed; for yourconvenience, recent versions should be available from PyPI.To use, just define a field in your model:: >>> from picklefield.fields import PickledObjectField ... class SomeObject(models.Model): ... args = PickledObjectField()and assign whatever you like (as long as it's picklable) to the field:: >>> obj = SomeObject() >>> obj.args = ['fancy', {'objects': 'inside'}] >>> you need to serialize an object with a PickledObjectField for transmissionto the browser, you may need to subclass the field and override the``value_to_string()`` method. Currently pickle fields are serialized asbase64-encoded pickles, which allows reliable deserialization, but such aformat is not convenient for parsing in the browser. By overriding``value_to_string()`` you can choose a more convenient serialization format.Here are the notes by taavi223, the original author:Incredibly useful for storing just about anything in the database (provided itis Pickle-able, of course) when there isn't a 'proper' field for the job.PickledObjectField is database-agnostic, and should work with any databasebackend you can throw at it. You can pass in any Python object and it willautomagically be converted behind the scenes. You never have to manually pickleor unpickle anything. Also works fine when querying; supports exact, in, andisnull lookups. It should be noted, however, that calling QuerySet.values()will only return the encoded data, not the original Python object.This PickledObjectField has a few improvements over the one in snippet #513.This one solves the DjangoUnicodeDecodeError problem when saving an objectcontaining non-ASCII data by base64 encoding the pickled output stream. Thisensures that all stored data is ASCII, eliminating the problem.PickledObjectField will now optionally use zlib to compress (and uncompress)pickled objects on the fly. This can be set per-field using the keywordargument "compress=True". For most items this is probably not worth the smallperformance penalty, but for Models with larger objects, it can be a real spacesaver.You can also now specify the pickle protocol per-field, using the protocolkeyword argument. The default of 2 should always work, unless you are trying toaccess the data from outside of the Django ORM.Worked around a rare issue when using the cPickle and performing lookups ofcomplex data types. In short, cPickle would sometimes output different streamsfor the same object depending on how it was referenced. This of course couldcause lookups for complex objects to fail, even when a matching object exists.See the docstrings and tests for more information.You can now use the isnull lookup and have it function as expected. Aconsequence of this is that by default, PickledObjectField has null=True set(you can of course pass null=False if you want to change that). If null=Falseis set (the default for fields), then you wouldn't be able to store a PythonNone value, since None values aren't pickled or encoded (this in turn is whatmakes the isnull lookup possible).You can now pass in an object as the default argument for the field without itbeing converted to a unicode string first. If you pass in a callable though,the field will still call it. It will not try to pickle and encode it.You can manually import dbsafe_encode and dbsafe_decode from if youwant to encode and decode objects yourself. This is mostly useful for decodingvalues returned from calling QuerySet.values(), which are still encodedstrings.Note: If you are trying to store other django models in the PickledObjectField,please see the comments for a discussion on the problems associated with doingthat. The easy solution is to put django models into a list or tuple beforeassigning them to the PickledObjectField.Update 9/2/09: Fixed the value_to_string method so that serialization shouldnow work as expected. Also added deepcopy back into dbsafe_encode, fixing #4above, since deepcopy had somehow managed to remove itself. This means thatlookups should once again work as expected in all situations. Also made thefield editable=False by default (which I swear I already did once before!)since it is never a good idea to have a PickledObjectField be user editable.-------Changes-------Changes in version 0.1.5======================== * Added support for South. * Changed default to null=False, as is common throughout Django.Changes in version 0.1.4======================== * Updated copyright statements.Changes in version 0.1.3======================== * Updated serialization tests (thanks to Michael Fladischer).Changes in version 0.1.2======================== * Added Simplified BSD licence.Changes in version 0.1.1======================== * Added test for serialization. * Added note about JSON serialization for browser. * Added support for different pickle protocol versions (thanks to Michael Fladischer).Changes in version 0.1====================== * First public release.--------Feedback--------There is a `home page `_with instructions on how to access the code repository.

**django-picklefield** provides an ... A pickled object field for Django ...

  • Freeware
  • 10 Kb
  • 147
  • Free

Review Django-picklefield

  • captcha
New HTML Editors software
  • Net Core PDF Generator  v.2021.3.1In .Net core, we convert HTML to PDF by using the IronPDF, HTML to PDF class and asking it to render. It will render any HTML file URL or string into a PDF document, including internal links, bookmarks, images, and so much more.
  • EnWeb HTML Editor  v.1.1EnWeb is a HTML source code editor for Windows that allows you to create and edit web pages. features include easy to use code generator dialogs, cross-browser compatibility, multi-document tab interface and syntax highlighting.
  • OrgChart JS  v.7.6.13A JavaScript library for building interactive Org-Charts, specifically tailored for displaying a company's organizational structure ...
  • TextPipe Lite  v.11.7.1TextPipe is the ultimate Webmaster tool for updating text. It handles an unlimited number of files and folders, and is unique in handling files of unlimited size. It performs one or more changes AT THE SAME TIME, and can search for MULTI-LINE text...
  • TracSQL  v.0.3The TracSQL project is a plugin for the Trac project management tool.
  • Chronicle for Linux  v.3.7Chronicle software is a small and fast blog compiler, written in Perl with minimal dependencies.