admin.py 文件源码

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

项目:gougo 作者: amaozhao 项目源码 文件源码
def choices(self, cl):
        # #### MPTT ADDITION START
        try:
            # EMPTY_CHANGELIST_VALUE has been removed in django 1.9
            from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
        except:
            EMPTY_CHANGELIST_VALUE = self.empty_value_display
        # #### MPTT ADDITION END
        yield {
            'selected': self.lookup_val is None and not self.lookup_val_isnull,
            'query_string': cl.get_query_string({}, [self.lookup_kwarg, self.lookup_kwarg_isnull]),
            'display': _('All'),
        }
        for pk_val, val, padding_style in self.lookup_choices:
            yield {
                'selected': self.lookup_val == smart_text(pk_val),
                'query_string': cl.get_query_string({
                    self.lookup_kwarg: pk_val,
                }, [self.lookup_kwarg_isnull]),
                'display': val,
                # #### MPTT ADDITION START
                'padding_style': padding_style,
                # #### MPTT ADDITION END
            }
        if (isinstance(self.field, ForeignObjectRel) and
                (self.field.field.null or isinstance(self.field.field, ManyToManyField)) or
                hasattr(self.field, 'rel') and
                (self.field.null or isinstance(self.field, ManyToManyField))):
            yield {
                'selected': bool(self.lookup_val_isnull),
                'query_string': cl.get_query_string({
                    self.lookup_kwarg_isnull: 'True',
                }, [self.lookup_kwarg]),
                'display': EMPTY_CHANGELIST_VALUE,
            }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号