[英]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.