I want to get the object from a queryset
accounts = group.get_external_accounts(include_sub_groups=True)
try:
account: StripeExternalAccount = accounts.get(account_id)
except StripeExternalAccount.DoesNotExist:
return Response(status=status.HTTP_400_BAD_REQUEST)
I have tried this. it works fine but i want to do it through try except
account: StripeExternalAccount = None
for acc in accounts:
if acc.id == int(account_id):
account = acc
break
if not account:
return Response(status=status.HTTP_400_BAD_REQUEST)