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)