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 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

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
In view.py

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

@method_decorator(login_required)
@method_decorator(manager_required(redirect_field_name="login"))
def dispatch(self, *args, **kwargs):
    return super(HomePageView, self).dispatch(*args, **kwargs)

def get_context_data(self, **kwargs):
    today = datetime.datetime.today()
    startdate = datetime.datetime(today.year, today.month, today.day, 0, 0, 0, 0)
    enddate = datetime.datetime(today.year, today.month, today.day, 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
    else:
        context["startdate"] = startdate.strftime('%Y') + '-' \
            + startdate.strftime('%m') + '-' + startdate.strftime('%d')
        context["enddate"] = enddate.strftime('%Y') + '-' \
            + enddate.strftime('%m') + '-' + enddate.strftime('%d')

    return context

in HTML

<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">