Exemplo n.º 1
0
    def make_value_from_form(self, value):
        """Convert a form value to a property value.

    This turns a key string or object into a model instance.
    """
        if value:
            if not isinstance(value, db.Model):
                value = db.get(value)
        return value
Exemplo n.º 2
0
  def make_value_from_form(self, value):
    """Convert a form value to a property value.

    This turns a key string or object into a model instance.
    """
    if value:
      if not isinstance(value, db.Model):
        value = db.get(value)
    return value
Exemplo n.º 3
0
    def clean(self, value):
        """Override Field.clean() to do reference-specific value cleaning.

    This turns a non-empty value into a model instance.
    """
        value = super(ModelChoiceField, self).clean(value)
        if not value:
            return None
        instance = db.get(value)
        if instance is None:
            raise db.BadValueError(self.error_messages['invalid_choice'])
        return instance
Exemplo n.º 4
0
  def clean(self, value):
    """Override Field.clean() to do reference-specific value cleaning.

    This turns a non-empty value into a model instance.
    """
    value = super(ModelChoiceField, self).clean(value)
    if not value:
      return None
    instance = db.get(value)
    if instance is None:
      raise db.BadValueError(self.error_messages['invalid_choice'])
    return instance