简体   繁体   English

int() 参数必须是字符串、类似字节的 object 或数字,而不是 'dict'

[英]int() argument must be a string, a bytes-like object or a number, not 'dict'

The function not entering into if condition, because round is dict and match_round is int, so showing error, how solve this? function没有进入if条件,因为round是dict,match_round是int,所以报错,怎么解决?

my modelviewset我的模型视图集

 def destroy(self, request, *args, **kwargs):
    gameevent = self.get_object().gameevent
    match_round = self.get_object().match_round
    print(gameevent)
    print(match_round)
    round = Matchscore.objects.filter(gameevent=gameevent, match_round=match_round).values_list("match_round",flat=True).aggregate(Max("match_round"))
    print(round)
    if round == match_round:
        Matchscore.objects.get(match_round=round).delete()
        response = {"result": "successfully removed"}
    else:
        response = {"result": "can't delete this round"}
    return Response(response)

try this,尝试这个,

 def destroy(self, request, *args, **kwargs):
    gameevent = self.get_object().gameevent
    match_round = self.get_object().match_round
    print(gameevent)
    print(match_round)
    round = Matchscore.objects.filter(gameevent=gameevent, match_round=match_round).values_list("match_round",flat=True).aggregate(Max("match_round"))['match_round__max']
    print(round)
    if round == match_round:
        Matchscore.objects.get(match_round=round).delete()
        response = {"result": "successfully removed"}
    else:
        response = {"result": "can't delete this round"}
    return Response(response)

If you want to compare Django DB objects for identity in the DB, ie sharing the same DB row, then test their pk for equality.如果您想比较 Django 个数据库对象在数据库中的身份,即共享相同的数据库行,然后测试它们的 pk 是否相等。

if a_round.pk == match_round.pk:

if by some other metric based on other fields, code this explicitly.如果通过基于其他字段的其他指标,请明确编码。

In the question, round is not a Django DB object at all, it's a values_list based on some filtered objects.在这个问题中, round根本不是 Django DB object ,它是一个基于一些过滤对象的values_list So you need to extract some values from the result of that query, and the corresponding values from match_round , and compare them.因此,您需要从该查询的结果中提取一些值,并从match_round中提取相应的值,然后比较它们。 I don't have sufficient insight into the problem to suggest the nature of that comparison.我对这个问题没有足够的洞察力来暗示这种比较的性质。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 总和抛出 `int() 参数必须是一个字符串,一个类似字节的 object 或一个数字,而不是'dict'` - Django aggregate sum throwing `int() argument must be a string, a bytes-like object or a number, not 'dict'` python中的数据增强引发错误“ int()参数必须是字符串,类似字节的对象或数字,而不是'dict'” - Data augmentation in python throws an error “int() argument must be a string, a bytes-like object or a number, not 'dict'” int()参数必须是字符串,类似字节的对象或数字,而不是“元组” - int() argument must be a string, a bytes-like object or a number, not 'tuple' int() 参数必须是字符串、类似字节的对象或数字,而不是 'QueryDict' - int() argument must be a string, a bytes-like object or a number, not 'QueryDict' int()参数必须是字符串,类似字节的对象或数字,而不是“列表” - int() argument must be a string, a bytes-like object or a number, not 'list' int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType” - int() argument must be a string, a bytes-like object or a number, not 'NoneType' int() 参数必须是字符串、类似字节的对象或数字,而不是“QuerySet” - int() argument must be a string, a bytes-like object or a number, not 'QuerySet' TypeError: int() 参数必须是一个字符串,一个类似字节的 object 或一个数字,而不是“NoneType”。 但我写了 int() - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'. But I wrote the int() int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType”,尝试使用我的网络摄像头进行对象检测 - int() argument must be a string, a bytes-like object or a number, not 'NoneType', trying to use my webcam for object detection 小鸭,int() 参数必须是一个字符串,一个类似字节的 object 或一个数字,而不是 'java.lang.String', - Duckling, int() argument must be a string, a bytes-like object or a number, not 'java.lang.String',
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM