Skip to content

Commit

Permalink
fix(wallet serializer): improve operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenepix38 committed Oct 21, 2023
1 parent 76c467e commit 72a7fa6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions django_napse/api/wallets/serializers/wallet_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ def get_value(self, instance) -> float:

def get_operations(self, instance) -> dict:
transactions = Transaction.objects.filter(Q(from_wallet=instance) | Q(to_wallet=instance)).order_by("created_at")
return {
"credits": CreditSerializer(instance.credits.all().order_by("created_at"), many=True).data,
"debits": DebitSerializer(instance.debits.all().order_by("created_at"), many=True).data,
"transactions": TransactionSerializer(transactions, many=True).data,
}
transactions_data = TransactionSerializer(transactions, many=True).data
credits_data = CreditSerializer(instance.credits.all().order_by("created_at"), many=True).data
debits_data = DebitSerializer(instance.debits.all().order_by("created_at"), many=True).data

# return {
# "credits": CreditSerializer(instance.credits.all().order_by("created_at"), many=True).data,
# "debits": DebitSerializer(instance.debits.all().order_by("created_at"), many=True).data,
# "transactions": TransactionSerializer(transactions, many=True).data,
# }
return credits_data + debits_data + transactions_data

0 comments on commit 72a7fa6

Please sign in to comment.