Saving Python Pickled objects in MySQL db

后端 未结 4 1657
北海茫月
北海茫月 2020-12-14 22:55

I am pickling Python Objects in Django and saving it in MySQL db. So far i have followed these simple rules:

  1. cPickle.dumps(object) #to convert

4条回答
  •  时光说笑
    2020-12-14 23:28

    You can try this, now! django-picklefield https://pypi.org/project/django-picklefield/

    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'}]
    >>> obj.save()
    

提交回复
热议问题