managers.py 文件源码

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

项目:minimum-entropy 作者: DistrictDataLabs 项目源码 文件源码
def punch_ballot(self, content=None, user=None, vote=0):
        """
        Essentially `update_or_create` with ContentType lookup
        """
        if content is None or user is None:
            raise TypeError("content and user are required for punch ballot")

        kwargs = {
            'content_type': ContentType.objects.get_for_model(content),
            'object_id': content.id,
            'user': user,
            'defaults': {
                'vote': vote,
            }
        }

        return self.update_or_create(**kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号