Remove Tx model

There was a split between a transaction request and an actual
transaction. This was kind of annoying because transactions were one-way
only, while transaction requests were two-way - which is what I believe
most transactions will be using. Tx model has been removed and the
responsibilities of it are covered by TxRequest. It simplifies
everything surrounding transactions, since we have only one model to
deal with instead of two.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-03-26 12:49:46 -04:00
parent 80ad39eb6f
commit c320f81181
7 changed files with 101 additions and 171 deletions

View File

@@ -12,7 +12,7 @@ from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.list import ListView
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
from trading.models import User, Commodity, MaxCommodityError, Tx, TxRequest
from trading.models import User, Commodity, MaxCommodityError, TxRequest
class IndexView(LoginRequiredMixin, TemplateView):
@@ -57,6 +57,21 @@ class TxRequestDetailView(DetailView):
template_name = "trading/t/detail.html"
model = TxRequest
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
tx = context["object"]
if self.request.user == tx.source:
context["sent"] = tx.source_sends
context["sent_amount"] = tx.source_amount
context["received"] = tx.dest_sends
context["received_amount"] = tx.dest_amount
else:
context["sent"] = tx.dest_sends
context["sent_amount"] = tx.dest_amount
context["received"] = tx.source_sends
context["received_amount"] = tx.source_amount
return context
class TxRequestListView(LoginRequiredMixin, ListView):
template_name = "trading/t/list.html"