From 66b70e69f383844ee15c7e9aaf0b55922ed52adf Mon Sep 17 00:00:00 2001 From: PA Date: Wed, 14 Aug 2019 16:42:05 +0200 Subject: [PATCH] Add transaction history list on the user --- apps/member/views.py | 11 ++++++++++- templates/member/profile_detail.html | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 37c47212..d664df70 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -9,9 +9,11 @@ from django.views.generic import CreateView, ListView, DetailView from django.http import HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm from django.urls import reverse_lazy +from django.db.models import Q from .models import Profile, Club from .forms import ProfileForm, ClubForm +from note.models.transactions import Transaction class UserCreateView(CreateView): """ @@ -39,9 +41,16 @@ class UserCreateView(CreateView): return super().form_valid(form) - class UserDetailView(LoginRequiredMixin,DetailView): model = Profile + + def get_context_data(slef,**kwargs): + context = super().get_context_data(**kwargs) + user = context['object'].user.note + user_transactions = \ + Transaction.objects.all().filter(Q(source=user) | Q(destination=user)) + context['history_list'] = user_transactions + return context class ClubCreateView(LoginRequiredMixin,CreateView): diff --git a/templates/member/profile_detail.html b/templates/member/profile_detail.html index 11f50f65..82be255a 100644 --- a/templates/member/profile_detail.html +++ b/templates/member/profile_detail.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n static pretty_money %} +{% load i18n static pretty_money django_tables2 %} {% block content %}

Compte n° {{ object.pk }}

@@ -24,4 +24,6 @@ {% trans 'Change password' %} + + {% render_table history_list %} {% endblock %}