English 中文(简体)
PickledObject Field(django-picklefield)的使用实例?
原标题:Examples of use for PickledObjectField (django-picklefield)?

http://blog.apps.chicagotribune.com/02/26/best-practices/“rel=“nofollow noreferer”>django dev Best practices 使用的模型领域,极为谨慎。

但是,在现实生活中,你将使用<代码>。 PickledObject Field,以解决哪些具体问题?

最佳回答

我们有一个社会网络“后台”系统,它像“后台信息”、“植被状况”、“植被朋友”等一些通用障碍。 每个后备班与用户之间的联系是“滴扬戈”模式,它使用户、背书名和全权证书得以保存。 现在可以想象有多少宽松的系统: o、便衣口、脸谱 obscure等。 在JSON野心中,我们把所有背书的紧缩数据都放在关于这一模式的字典上,该模型储存在桶子里,我们就能够把任何东西放入它。

问题回答

http://docs.python.org/library/pickle.html 总的来说,使用这一工具的理由很少;初等干事比较安全,而且更方便。

你可以肯定地替代一名PickledObject Field with JSON和一些额外的逻辑,从JSON中制造一个物体。 归根结底,在考虑使用PickledObject或JSON+logic时,您的用途案例正在把一个灰色物体编成你的数据库。 如果你能够相信斯图尔特的数据,并且知道这些数据将永远可以序列化,那么你就可以合理地利用PickledObject油田。 在我的案件中(我不使用jan,但这仍应适用),我有两种不同的物体类型,可以进入我的PickledObject油田,其定义不断变。 我并非不断更新我的“智者”教义,以制造一种来自“智者”价值观的物体,而我只是利用一个PickledObject油田,仅仅储存不同的物体,然后以完全可行的形式检索这些物体(召回其功能)。 洞穴: 如果你通过PickledObject油田储存物体,那么你会改变物体定义,然后取回物体,旧物体可能难以符合新物体的定义(取决于您的变化)。

有待解决的问题是:convenience界定和处理由许多部分组成的复合物。

You can turn each part type into a Model and connect them via ForeignKeys. Or you can turn each part type into a class, dictionary, list, tuple, enum or whathaveyou to your liking and use PickledObjectField to store and retrieve the whole beast in one step.

如果你永远不会单独操纵部分,那么这种做法就有意义,只是整个复杂的目标。

Real life example

在我的申请中,有RQdef基本上代表某种基本结构的一类物体(如果是可治愈的,请见here

  • RQdefs consist of several Aspects and some fixed attributes.
  • Aspects consist of one or more Facets and some fixed attributes.
  • Facets consist of two or more Levels and some fixed attributes.
  • Levels consist of a few fixed attributes.
  • Overall, a typical RQdef will have about 20-40 parts.
  • An RQdef is always completely constructed in a single step before it is stored in the database and it is henceforth never modified, only read (but read frequently).

<代码>PickledObject Field比每个RQdef的一套四种模型和20-40项物体更方便、更高效。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签