【问题标题】:Python model of Google Contact for appengine datastore用于 appengine 数据存储的 Google Contact 的 Python 模型
【发布时间】:2012-06-11 22:08:08
【问题描述】:

我想从Google API v3 保存AppEngine datastore 上的联系人。我想知道存储这些数据的最佳方式是什么,尤其是在已经有模型的情况下!

看着the sources of gdata,我发现了一个很有趣的开始。但这只是python中的数据建模,而不是数据存储。

问题:这个模型是否已经存在于 python 中?

如果没有:

问题:从头开始的最佳方式是什么?

Python 中联系人的开始示例:

class Contact(db.Model):
    """
    https://developers.google.com/gdata/docs/2.0/elements?hl=fr#gdContactKind
    https://developers.google.com/appengine/docs/python/datastore/datamodeling
    """

    content = db.Text()
    """atom:content Notes about the contact."""

    link = db.ListProperty(Link,indexed=False,default=[])
    """atom:link*   Links to related information. Specifically, atom:link[@rel='alternate'] links to an HTML page describing the contact."""

    title = db.StringProperty()
    """atom:title   Contact's name. This field is read only. To modify the contact's name, see gd:name."""

    email = db.ListProperty(Email,indexed=False,default=[])
    """gd:email*    Email addresses."""

    """etc..."""

class Link(db.Model):
    """
    Link
    """
    link = db.LinkProperty()

class Email(db.Model):
    """
    Email
    """
    email_address = db.EmailProperty()


class EmailImParent(db.Model):
  address = db.StringProperty()
  label = db.StringProperty()
  rel = db.StringProperty()
  primary = db.StringProperty()


class Email(db.Model,EmailImParent):
  """
  The gd:email element.
  """
  email =  db.EmailProperty()
  display_name = db.StringProperty()

【问题讨论】:

    标签: python google-app-engine database-design gdata google-contacts-api


    【解决方案1】:

    我认为每个人都在自己动手。这很容易做到,您可以查看AE-BaseApp/Python 并从 Github 链接中查看代码。我有一些新代码将在不久的将来更新,其中包含对联系模型的一些改进。 (更新后的代码目前已被破坏,因为黑客可以在 http 和 https here 上进行登录)

    【讨论】:

    • 我查看了您的代码,但没有找到与联系人实体相关的任何内容。您是否计划在您的目录中添加实体/models/
    • 查看 UserProfile.py 文件。这是我在此应用程序中用于联系人的内容。我创建了一个名为 ProfileCrud 的类,用于将来的一些您在技术上不需要的 api 原因。如果您认为不会对其进行太多修改,则可以只使用该类的定义,但您需要将用户 id 变量添加到它们从调用 ProfileCrud 继承的定义中。没有额外的类查找也有一些性能改进。我尚未对其进行基准测试以知道它是否重要,但您应该意识到这一点。
    猜你喜欢
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多