我编写了一个方法来检查一个属性,如果有一个艺术家的 sell=False,则返回 False,否则返回 True。
def check_selling(track, excludes):
"""
Returns True if all track's artists are allowed for selling. False otherwise
"""
for artist in track.artists.all():
if not artist.selling:
excludes.append(track.pk)
return False
return True
我怎样才能最小化这个?
我试过了:
def check_selling(track, excludes):
res = excludes.append(track.pk) if not [artist.selling for artist in track.artists.all()] else True
return res or False
但是 [False] 或 [True] 导致列表理解 [artist.sales for artist in track.artists.all()] 总是给出 True...