widgets.py 文件源码

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

项目:django-content-gallery 作者: Kemaweyan 项目源码 文件源码
def _filter_choices(self):
        """
        Removes the ContentType objects that have not
        the 'gallery_visible' attribute set to True.
        """
        filtered_choices = []
        # initially self.choices contains all content types
        for choice in self.choices:
            try:
                if choice[0] == "":
                    # add the empty choice
                    filtered_choices.append(choice)
                    continue
                # get the content type and determine the model
                ctype = ContentType.objects.get(pk=int(choice[0]))
                model_class = ctype.model_class()
                if model_class.gallery_visible:
                    # add the choice if the model has the 'gallery_visible'
                    # attribute and it's set to True
                    filtered_choices.append(choice)
            except:
                # the model has not the 'gallery_visible' attribute
                pass
        # replace original choices
        self.choices = filtered_choices
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号