2019-08-15 21:08:15 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import django_tables2 as tables
|
2020-02-16 21:29:27 +00:00
|
|
|
from django.db.models import F
|
|
|
|
|
2019-08-15 21:08:15 +00:00
|
|
|
from .models.transactions import Transaction
|
|
|
|
|
|
|
|
|
|
|
|
class HistoryTable(tables.Table):
|
|
|
|
class Meta:
|
2020-02-18 11:31:15 +00:00
|
|
|
attrs = {
|
|
|
|
'class':
|
|
|
|
'table table-bordered table-condensed table-striped table-hover'
|
|
|
|
}
|
2019-08-15 21:08:15 +00:00
|
|
|
model = Transaction
|
|
|
|
template_name = 'django_tables2/bootstrap.html'
|
2020-02-18 11:31:15 +00:00
|
|
|
sequence = ('...', 'total', 'valid')
|
2019-08-15 21:08:15 +00:00
|
|
|
|
2020-02-18 11:31:15 +00:00
|
|
|
total = tables.Column() #will use Transaction.total() !!
|
2019-08-15 21:08:15 +00:00
|
|
|
|
|
|
|
def order_total(self, QuerySet, is_descending):
|
|
|
|
# needed for rendering
|
|
|
|
QuerySet = QuerySet.annotate(
|
2020-02-18 11:31:15 +00:00
|
|
|
total=F('amount') *
|
|
|
|
F('quantity')).order_by(('-' if is_descending else '') + 'total')
|
2019-08-15 21:08:15 +00:00
|
|
|
return (QuerySet, True)
|