relfield.py 文件源码

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

项目:MxOnline 作者: myTeemo 项目源码 文件源码
def build_attrs(self, attrs={}, **kwargs):
        to_opts = self.rel.to._meta
        if "class" not in attrs:
            attrs['class'] = 'select-search'
        else:
            attrs['class'] = attrs['class'] + ' select-search'
        attrs['data-search-url'] = self.admin_view.get_admin_url(
            '%s_%s_changelist' % (to_opts.app_label, to_opts.model_name))
        attrs['data-placeholder'] = _('Search %s') % to_opts.verbose_name
        attrs['data-choices'] = '?'
        if self.rel.limit_choices_to:
            for i in list(self.rel.limit_choices_to):
                attrs['data-choices'] += "&_p_%s=%s" % (i, self.rel.limit_choices_to[i])
            attrs['data-choices'] = format_html(attrs['data-choices'])

        return super(ForeignKeySearchWidget, self).build_attrs(attrs, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号