Date Range POST startdate-enddate

Trying to add DateRange to job list but cant get POST to work.
Yen I know IDK what I’m doing :slight_smile:
Getting Method Not Allowed (POST): /manager/
Added *args, **kwargs as one of the post suggested but same result
Dont know if need to be changed and how.

class DateRangeJobListJson(BaseDatatableView):

def ShowDateRange(self, request, *args, **kwargs):
    if request.HttpRequest.method == 'POST':
        start_date = datetime.datetime(fromdate)
        end_date = datetime.datetime(todate)

model = Job
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"))
        return super(DateRangeJobListJson, self).render_column(row, column)

def get_initial_queryset(self):
    today =
    start_date = datetime.datetime(
        today.year, today.month,, 0, 0, 0, 0)
    end_date = datetime.datetime(
        today.year, today.month,, 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

When you’re posting an error, please post the complete error message. Frequently, there’s a lot of useful information contained within it.

Also, it’s helpful to have more details about what was going on when the error occurred.
(See How do I ask a good question? - Help Center - Stack Overflow for some ideas in this regard.)

Also, when posting code, enclose the code between lines of three backticks - `. This means you’ll have a line of ```, then your code, then another line of ```. (The lines of ``` have to be on their own, not part of another line.) This will preserve the formatting and spacing of the code, which is critical with Python.

POST was a bad choice, this page doesn’t use server side processing,
Need GET startdate and enddate
Trying to implement that, will update you is doesn’t work

Got it working now using GET and ajax

class HomePageView(TemplateView):
template_name = 'manager/test.html'

def dispatch(self, *args, **kwargs):
    return super(HomePageView, self).dispatch(*args, **kwargs)

def get_context_data(self, **kwargs):
    today =
    startdate = datetime.datetime(today.year, today.month,, 0, 0, 0, 0)
    enddate = datetime.datetime(today.year, today.month,, 23, 59, 59, 99)
    context = super().get_context_data(**kwargs)

    start_date = self.request.GET.get('startdate')
    end_date = self.request.GET.get('enddate')
    if start_date and end_date is not None:
        context["startdate"] = start_date
        context["enddate"] = end_date
        context["startdate"] = startdate.strftime('%Y') + '-' \
            + startdate.strftime('%m') + '-' + startdate.strftime('%d')
        context["enddate"] = enddate.strftime('%Y') + '-' \
            + enddate.strftime('%m') + '-' + enddate.strftime('%d')

    return context


<form id="date_range" action="/manager"  method="GET" class="d-flex justify-content-center">
<p><label for="Start date:"</label>
<input type="date" id="startdate" name="startdate">
<input type="date" id="enddate" name="enddate">
<input class="btn btn-dark" type="submit">