python类AdminFileWidget()的实例源码

forms.py 文件源码 项目:pyconjp-website 作者: pyconjp 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _construct_form(self, i, **kwargs):
        form = super(SponsorBenefitsInlineFormSet, self)._construct_form(i, **kwargs)

        # only include the relevant data fields for this benefit type
        fields = form.instance.data_fields()
        form.fields = dict((k, v) for (k, v) in form.fields.items() if k in fields + ["id"])
        for field in fields:
            # don't need a label, the form template will label it with the benefit name
            form.fields[field].label = ""

            # provide word limit as help_text
            if form.instance.benefit.type in ["text", "richtext"] and form.instance.max_words:
#                form.fields[field].help_text = u"maximum %s characters" % form.instance.max_words
                form.fields[field].help_text = u"Japanese 200 words. English 100 words."

            # use admin file widget that shows currently uploaded file
            if field == "upload":
                form.fields[field].widget = AdminFileWidget()

        return form
forms.py 文件源码 项目:django-bootstrap4 作者: zostera 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def is_widget_required_attribute(widget):
    """
    Is this widget required?
    """
    if not widget.is_required:
        return False
    if isinstance(widget, (AdminFileWidget, HiddenInput, FileInput, CheckboxInput, CheckboxSelectMultiple)):
        return False
    return True


问题


面经


文章

微信
公众号

扫码关注公众号