summaryrefslogtreecommitdiff
path: root/app/trading/views.py
blob: a32d571879f904ca44901a2a1fe3a0c8c549fb03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from django.shortcuts import render
from django.views.generic.edit import FormView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from utils.views import PaginatedListView

from .models import OptionsTrade, LuxTrade


class OptionsTradeResultsView(PaginatedListView):
    model = OptionsTrade

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(OptionsTradeResultsView, self).get_context_data(**kwargs)
        return context

class TradeModelFormView(CreateView):
    model = LuxTrade
    fields = ['symbol', 'status', 'entry_price', 'stop_price', 'target_price', 'shares', 'is_wanderer']
    success_url = '/trading/'
    template_name = 'trading/create_form.html'

class LuxTradeDetailView(UpdateView):
    model = LuxTrade
    fields = ['symbol', 'status', 'entry_price', 'stop_price', 'target_price', 'shares', 'close_price', 'notes', 'is_wanderer']
    template_name = 'trading/update_form.html'
    success_url = '/trading/'

class LuxTradeListView(PaginatedListView):
    model = LuxTrade
    template_name = 'trading/list.html'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(LuxTradeListView, self).get_context_data(**kwargs)
        context['open_trades'] = LuxTrade.objects.filter(status=0)
        context['watch_trades'] = LuxTrade.objects.filter(status=2)
        return context

    def get_queryset(self):
        queryset = super(LuxTradeListView, self).get_queryset()
        return queryset.filter(status=1)