boundfield.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码
def value(self):
        """
        Returns the value for this BoundField, using the initial value if
        the form is not bound or the data otherwise.
        """
        if not self.form.is_bound:
            data = self.form.initial.get(self.name, self.field.initial)
            if callable(data):
                if self._initial_value is not UNSET:
                    data = self._initial_value
                else:
                    data = data()
                    # If this is an auto-generated default date, nix the
                    # microseconds for standardized handling. See #22502.
                    if (isinstance(data, (datetime.datetime, datetime.time)) and
                            not self.field.widget.supports_microseconds):
                        data = data.replace(microsecond=0)
                    self._initial_value = data
        else:
            data = self.field.bound_data(
                self.data, self.form.initial.get(self.name, self.field.initial)
            )
        return self.field.prepare_value(data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号