1👍
✅
You filter with:
@api_view(['GET'])
@permission_classes([IsAuthenticated])
def getTransactions(request):
transactions = Transaction.objects.filter(account__user=request.user)
serializer = TransactionSerializer(transactions, many=True)
return Response(serializer.data)
Here we thus retrieve Transaction
s for which the account
refers to an Account
object with request.user
as user
.
Note: It is normally better to make use of the
settings.AUTH_USER_MODEL
[Django-doc] to refer to the user model, than to use theUser
model [Django-doc] directly. For more information you can see the referencing theUser
model section of the documentation.
Source:stackexchange.com