I'm in a little gambit with this question here "conversion from method to Decimal is not supported django" error where adding the () gives me an error 'DeferredAttribute' object is not callable
and removing them gives me another conversion from DeferredAttribute to Decimal is not supported
(My current error with the code below)
My goal is two take my 3 values and figure out what the profit or loss is:
Profit_long = (price 1 - price 2) * size
*I'm not entriely sure if the math syntax is right yet because the above error message won't let me get that far. From what I've read as long as those variables are integers the math syntax should be right. Not sure if it will work with decimals. That's step two. First I need to solve the above issue.
views.py
class TradeDetailView(DetailView):
template_name = 'tj/cp/trade/detail.html'
queryset = Trade.objects.all()
def get_object(self):
id_ = self.kwargs.get("id")
return get_object_or_404(Trade, id=id_)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
entry_price = Decimal(Trade.entry_price)
exit_price = Decimal(Trade.entry_price)
size = Decimal(Trade.size)
context['profit_long'] = (entry_price - exit_price) * size
return context
models.py
class Trade(models.Model):
...
size = models.DecimalField(null=True, blank=True, max_digits=50, decimal_places=2)
entry_price = models.DecimalField(null=True, blank=True, max_digits=50, decimal_places=2)
exit_price = models.DecimalField(null=True, blank=True, max_digits=50, decimal_places=2)
...