mixins.py 583 B

123456789101112131415
  1. class TransactionsMixin:
  2. """
  3. TransactionMixin are essentially just a type of class mixin
  4. when define common functions for all Viewsets
  5. """
  6. def get_filtered_transactions(self):
  7. date_from = self.request.query_params.get('date_from', None)
  8. date_to = self.request.query_params.get('date_from', None)
  9. transactions = self.user.transactions
  10. if date_from:
  11. transactions = transactions.filter(date__gte=date_from)
  12. if date_to:
  13. transactions = transactions.filter(date__lte=date_to)
  14. return transactions