yceruto/django-ajax

Getting code 400 in browser

ColeDrain opened this issue · 3 comments

Good day Sir. Love the idea of this package.
I have been trying to get this to work on my project, but in my browser I keep getting 400 Bad request with a blank page. I even followed the example in the readme, still not working.

My specs:
Django 3.0.6
Python 3.7

I am suspecting this doesn't work with Django 3.

Your response will be appreciated.

Hi, django 3 support was recently added to the test suite. Can you describe your problem in detail? Thanks!

Here is my implementation of the same and I am getting 400 bad request.

import datetime
from django.views.generic import TemplateView
from django_ajax.mixin import AJAXMixin


from wash_bookings.models import Booking
from wash_authentication.models import (
    User, DriverUser, ClientUser
)

# Create your views here.


class IndexView(AJAXMixin, TemplateView):
    template_name = 'index.html'

    def get_context_data(self, *args, **kwargs):
        context = super(IndexView, self).get_context_data(*args, **kwargs)
        context['bookings'] = list(
            Booking.objects.filter(
                booking_date=datetime.date.today()
            ).exclude(
                booking_status='COMPLETE'
            ).values(
                'client_id__name',
                'driver_id__name',
                'booking_date',
                'booking_time',
                'service_id__vehicle_category__name',
                'extra_service',
                'booking_status',
                'booking_total'
            )
        )
        context['top_wash'] = list(
            Booking.objects.order_by(
                '-booking_total'
            ).filter(
                booking_date=datetime.date.today()
            ).values(
                'client_id__name',
                'booking_date',
                'booking_time',
                'service_id__vehicle_category__name',
                'service_id__package_name',
                'extra_service',
                'booking_status',
                'booking_total'
            )
        )
        context['drivers'] = list(DriverUser.objects.values())
        context['clients'] = list(ClientUser.objects.values())
        context['staffusers'] = list(User.objects.filter(staff=True).values())
        # print(context)
        return context

Here is my implementation of the same and I am getting 400 bad request.

import datetime
from django.views.generic import TemplateView
from django_ajax.mixin import AJAXMixin


from wash_bookings.models import Booking
from wash_authentication.models import (
    User, DriverUser, ClientUser
)

# Create your views here.


class IndexView(AJAXMixin, TemplateView):
    template_name = 'index.html'

    def get_context_data(self, *args, **kwargs):
        context = super(IndexView, self).get_context_data(*args, **kwargs)
        context['bookings'] = list(
            Booking.objects.filter(
                booking_date=datetime.date.today()
            ).exclude(
                booking_status='COMPLETE'
            ).values(
                'client_id__name',
                'driver_id__name',
                'booking_date',
                'booking_time',
                'service_id__vehicle_category__name',
                'extra_service',
                'booking_status',
                'booking_total'
            )
        )
        context['top_wash'] = list(
            Booking.objects.order_by(
                '-booking_total'
            ).filter(
                booking_date=datetime.date.today()
            ).values(
                'client_id__name',
                'booking_date',
                'booking_time',
                'service_id__vehicle_category__name',
                'service_id__package_name',
                'extra_service',
                'booking_status',
                'booking_total'
            )
        )
        context['drivers'] = list(DriverUser.objects.values())
        context['clients'] = list(ClientUser.objects.values())
        context['staffusers'] = list(User.objects.filter(staff=True).values())
        # print(context)
        return context

What could be wrong. I need the template to refresh automatically