当前位置: 首页>>代码示例>>Python>>正文


Python db.StringProperty方法代码示例

本文整理汇总了Python中google.appengine.ext.db.StringProperty方法的典型用法代码示例。如果您正苦于以下问题:Python db.StringProperty方法的具体用法?Python db.StringProperty怎么用?Python db.StringProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.ext.db的用法示例。


在下文中一共展示了db.StringProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_prefix_properties

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import StringProperty [as 别名]
def add_prefix_properties(model_class, *properties):
    """Adds indexable properties to a model class to support prefix queries.
    All properties ending in '_' are extra properties.  The 'properties'
    arguments should be names of existing string properties on the class."""
    for property in properties:
        # This property contains a copy of the entire string normalized.
        setattr(model_class, property + '_n_', db.StringProperty())

        # This property contains just the first character, normalized.
        setattr(model_class, property + '_n1_', db.StringProperty())

        # This property contains just the first two characters, normalized.
        setattr(model_class, property + '_n2_', db.StringProperty())

    # Record the prefix properties.
    if not hasattr(model_class, '_prefix_properties'):
        model_class._prefix_properties = []
    model_class._prefix_properties += list(properties)

    # Update the model class.
    db._initialize_properties(
        model_class, model_class.__name__, model_class.__bases__,
        model_class.__dict__) 
开发者ID:google,项目名称:personfinder,代码行数:25,代码来源:prefix.py

示例2: get_TextField

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import StringProperty [as 别名]
def get_TextField(kwargs):
    """
    Returns a ``TextField``, applying the ``db.StringProperty`` length limit
    of 500 bytes.
    """
    kwargs['validators'].append(validators.length(max=500))
    return f.TextField(**kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:db.py

示例3: convert_StringProperty

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import StringProperty [as 别名]
def convert_StringProperty(model, prop, kwargs):
    """Returns a form field for a ``db.StringProperty``."""
    if prop.multiline:
        kwargs['validators'].append(validators.length(max=500))
        return f.TextAreaField(**kwargs)
    else:
        return get_TextField(kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:db.py

示例4: get_form_field

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import StringProperty [as 别名]
def get_form_field(self, **kwargs):
    """Return a Django form field appropriate for a string property.

    This sets the widget default to forms.Textarea if the property's
    multiline attribute is set.
    """
    defaults = {}
    if self.multiline:
      defaults['widget'] = forms.Textarea
    defaults.update(kwargs)
    return super(StringProperty, self).get_form_field(**defaults) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:13,代码来源:djangoforms.py

示例5: save

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import StringProperty [as 别名]
def save(self, commit=True):
    """Save this form's cleaned data into a model instance.

    Args:
      commit: optional bool, default True; if true, the model instance
        is also saved to the datastore.

    Returns:
      A model instance.  If a model instance was already associated
      with this form instance (either passed to the constructor with
      instance=...  or by a previous save() call), that same instance
      is updated and returned; if no instance was associated yet, one
      is created by this call.

    Raises:
      ValueError if the data couldn't be validated.
    """
    if not self.is_bound:
      raise ValueError('Cannot save an unbound form')
    opts = self._meta
    instance = self.instance
    if instance is None:
      fail_message = 'created'
    else:
      fail_message = 'updated'
    if self.errors:
      raise ValueError("The %s could not be %s because the data didn't "
                       'validate.' % (opts.model.kind(), fail_message))
    cleaned_data = self._cleaned_data()
    converted_data = {}
    propiter = itertools.chain(
      opts.model.properties().iteritems(),
      iter([('key_name', StringProperty(name='key_name'))])
      )
    for name, prop in propiter:
      value = cleaned_data.get(name)
      if value is not None:
        converted_data[name] = prop.make_value_from_form(value)
    try:
      if instance is None:
        instance = opts.model(**converted_data)
        self.instance = instance
      else:

        for name, value in converted_data.iteritems():
          if name == 'key_name':

            continue
          setattr(instance, name, value)
    except db.BadValueError, err:
      raise ValueError('The %s could not be %s (%s)' %
                       (opts.model.kind(), fail_message, err)) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:54,代码来源:djangoforms.py


注:本文中的google.appengine.ext.db.StringProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。