Trying to add DateRange to job list but cant get POST to work.
Yen I know IDK what I’m doing
Getting Method Not Allowed (POST): /manager/
Added *args, **kwargs as one of the post suggested but same result
Dont know if url.py need to be changed and how.
class DateRangeJobListJson(BaseDatatableView):
def ShowDateRange(self, request, *args, **kwargs):
if request.HttpRequest.method == 'POST':
fromdate=request.POST.get('startdate')
todate=request.POST.get('enddate')
start_date = datetime.datetime(fromdate)
end_date = datetime.datetime(todate)
model = Job
today = datetime.datetime.today()
columns = ['user', 'work_order', 'customer_name',
'address', 'job_type', 'tbc', 'created_at', 'updated_at', 'calculate_total']
order_columns = ['user', 'work_order', 'customer_name',
'address', 'job_type', 'tbc', 'created_at', 'updated_at', 'calculate_total']
max_display_length = 5000
def render_column(self, row, column):
settings_time_zone = timezone(settings.TIME_ZONE)
if column == "calculate_total" and row.calculate_total:
return escape("$" + format(row.calculate_total(), '.2f'))
if column == "tbc" and row.tbc():
return escape(row.tbc())
if column == "get_tech_name" and row.get_tech_name():
return escape(row.get_tech_name().first_name + " " + row.get_tech_name().last_name)
if column == "created_at" and row.created_at:
return escape(row.created_at.strftime("%m-%d-%Y %H:%M:%S"))
if column == "updated_at" and row.updated_at:
return escape(row.updated_at.strftime("%m-%d-%Y %H:%M:%S"))
else:
return super(DateRangeJobListJson, self).render_column(row, column)
def get_initial_queryset(self):
today = datetime.datetime.today()
start_date = datetime.datetime(
today.year, today.month, today.day, 0, 0, 0, 0)
end_date = datetime.datetime(
today.year, today.month, today.day, 23, 59, 59, 99)
# "2021-01-16 00:00:00", "2021-01-31 23:59:59"])start_date, end_date])#
# "2021-01-01 00:00:00", "2021-01-15 23:59:59"])
return self.model.objects.filter(created_at__range=[start_date, end_date])
def paging(self, qs):
return qs