list_edit_drivers.html -this is html file for showing data at front end
$(document).ready(function () {
$.extend(true, $.fn.dataTable.defaults, {
columnDefs: [
{
targets: '_all',
defaultContent: ''
}
]
});
var table = $('#drivers').DataTable({
"pageLength": 100,
"serverSide": true,
"bSearchable":true,
"dom": 'blfrtip',
"ajax": "/fleet/dt/editdrivers/?format=datatables&city_id={{city_id}}",
"columns": [
{
"data": "employee_id",
"mRender": function (data, type, full) {
return '<a href="/fleet/driver/list_drivers/{{city_id}}/view/' + full.id + '">' + full.employee_id + '</a>';
123 }
},
{
"data": "uber_name"
},
{
"data": "mobile"
},
{
"data": "uber_device_no"
},
{
"data": "aadhar_no",
"bVisible": false,
},
{
"data": "location.name"
},
{
"data": "status"
},
{
"data": "id",
"bSortable": false,
"mRender": function (data, type, full) {
return '<a class="btn btn-sm btn-primary" href="/fleet/driver/list_drivers/{{city_id}}/edit/' + full.id + '">' + 'Edit' + '</a>';
}
}]
});
});
urls.py -ajax call DriverViewSet url and html render list_edit_drivers url
router.register(r'dt/editdrivers', views.DriverViewSet)
path('driver/list_drivers', views.list_edit_drivers, name='list_edit_drivers')
views.py
@method_decorator(login_required, name='dispatch')
class DriverViewSet(viewsets.ModelViewSet):
queryset = Driver.objects.filter(is_active=1)
serializer_class = DriverEditListSerializer
def get_queryset(self):
queryset = Driver.objects.filter(is_active=1, city_id=self.request.GET.get('city_id'))
return queryset
@login_required
def list_edit_drivers(request):
driver = Driver.objects.filter(city_id=request.session['global_city_id'])
context = {
'menu_hiring': 'active',
'submenu_driver_edit_list': 'active',
'driver': driver,
'city_id': request.session['global_city_id']
}
return render(request, 'hiringprocess/list_edit_drivers.html', context=context)
serializers.py
class DriverEditListSerializer(serializers.ModelSerializer):
city = CitySerializer(read_only=True)
location = LocationSerializer()
class Meta:
model = Driver
fields = ( 'id','employee_id','employer', 'name','uber_name','uber_device_no', 'mobile', 'location', 'city','shift','status', 'aadhar_no')
** I need to this sql query implement for change logic, i don’t need to change existing field name and all, only change logic based on below mention sql query raw query or ORM both okay for me kindly help me out, i am stuck here **
SELECT *
from fleet_driver
left join fleet_hiring on fleet_driver.id = fleet_hiring.driver_id
WHERE (fleet_driver.id < 4253 )
or (fleet_driver.id >= 4253
and (fleet_hiring.status = 'Allocation Completed' or
fleet_hiring.status = 'Training Completed'))
models.py
class Driver(BaseModel):
employee_id = models.CharField(max_length=8,unique=True,null=True, default=True) name = models.CharField(max_length=255)
uber_name = models.CharField(max_length=255, null=True, blank=True)
mobile = models.CharField(max_length=20,unique=True,null=True, blank=True) uber_device_no = models.CharField(max_length=20,null=True,
blank=True)
city = models.ForeignKey(City,models.CASCADE,verbose_name='City',null=True, blank=True)
location = models.ForeignKey(Location,models.CASCADE,verbose_name='Location',null=True, blank=True)
status = EnumField(choices=['WORKING','ON_LEAVE', 'EXIT', 'REJOINED'], null=True)
class Hiring(BaseModel):
STATUS_CHOICES = (('', 'Type...'),
('HR Interview Pass', 'HR Interview Pass'),
('HR Interview Fail', 'HR Interview Fail'),
('Driving Test Pass', 'Driving Test Pass'),
('Driving Test Fail', 'Driving Test Fail'),
('Test Not Interested', 'Test Not Interested'),
('Test Pending', 'Test Pending'),
('Training Completed', 'Training Completed'),
('Training Pending', 'Training Pending'),
('Onboard', 'Onboard'),
('Allocation Completed', 'Allocation Completed'))
status = models.CharField(max_length = 255,choices=STATUS_CHOICES, null=True, blank=True)
driver = models.OneToOneField(Driver,models.CASCADE,related_name='driver',verbose_name=