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)
评论列表
文章目录