first commit
This commit is contained in:
26
helpers.py
Normal file
26
helpers.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import jdatetime
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
class CustomPagination(PageNumberPagination):
|
||||
page_size = 10
|
||||
page_size_query_param = 'page_size'
|
||||
max_page_size = 100
|
||||
|
||||
|
||||
def convert_to_miladi(year=None, month=None, day=None):
|
||||
date = jdatetime.datetime(year, month, day).togregorian()
|
||||
return date
|
||||
|
||||
|
||||
def build_query(fields, value):
|
||||
query = Q()
|
||||
for field in fields:
|
||||
query |= Q(**{f"{field}__icontains": value})
|
||||
return query
|
||||
|
||||
|
||||
def build_calculation(queryset, column_name, aggregate_func):
|
||||
result = queryset.aggregate(total=aggregate_func(column_name))
|
||||
return result['total'] or 0
|
||||
Reference in New Issue
Block a user