mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
create Custom history table
This commit is contained in:
parent
6779b9dac2
commit
a84031405e
@ -106,6 +106,10 @@ class Transaction(models.Model):
|
|||||||
self.destination.save()
|
self.destination.save()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def total(self):
|
||||||
|
return self.amount*self.quantity
|
||||||
|
|
||||||
|
|
||||||
class MembershipTransaction(Transaction):
|
class MembershipTransaction(Transaction):
|
||||||
membership = models.OneToOneField(
|
membership = models.OneToOneField(
|
||||||
|
20
apps/note/tables.py
Normal file
20
apps/note/tables.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import django_tables2 as tables
|
||||||
|
from .models.transactions import Transaction
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryTable(tables.Table):
|
||||||
|
class Meta:
|
||||||
|
attrs = {'class':'table table-bordered table-condensed table-striped table-hover'}
|
||||||
|
model = Transaction
|
||||||
|
template_name = 'django_tables2/bootstrap.html'
|
||||||
|
sequence = ('...','total','valid')
|
||||||
|
|
||||||
|
total = tables.Column() #will use Transaction.total() !!
|
||||||
|
|
||||||
|
def order_total(self, QuerySet, is_descending):
|
||||||
|
# needed for rendering
|
||||||
|
QuerySet = QuerySet.annotate(
|
||||||
|
total=F('amount') * F('quantity')
|
||||||
|
).order_by(('-' if is_descending else '') + 'total')
|
||||||
|
return (QuerySet, True)
|
Loading…
Reference in New Issue
Block a user