find route limit slice
This commit is contained in:
SDE
2023-08-29 13:31:00 +03:00
parent de0446c799
commit c8c0f43d4d
2 changed files with 20 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ from django.contrib import admin
class Admin_Route(Admin_Trans_BaseModel):
list_display = [
'id', 'type_transport', 'cargo_type',
'id', 'owner_type', 'type_transport', 'cargo_type',
'departure_DT', 'from_address_point', 'from_place',
'arrival_DT', 'to_place', 'owner',
'order', 'modifiedDT', 'createDT'
@@ -12,4 +12,7 @@ class Admin_Route(Admin_Trans_BaseModel):
list_display_links = ['id']
list_filter = ['owner_type', 'type_transport', 'cargo_type', 'from_place', 'arrival_DT', 'modifiedDT', 'createDT']
search_fields = ['owner__first_name', 'owner__last_name']
admin.site.register(Route,Admin_Route)

View File

@@ -15,6 +15,9 @@ def get_routes_Dict(user=None, data=None):
'owner': user
})
from_el = None
to_el = None
if data:
for key, val in data.items():
if val:
@@ -25,11 +28,23 @@ def get_routes_Dict(user=None, data=None):
if weight_list[1]:
kwargs.update({f'{key}__lte': int(weight_list[1])})
if key not in (
'from_address_point_txt', 'to_address_point_txt', 'csrfmiddlewaretoken', 'sort', 'weight',
'from_address_point_txt', 'to_address_point_txt', 'csrfmiddlewaretoken', 'sort', 'weight',
'from_el', 'to_el'
):
kwargs.update({key: val})
if key == 'from_el':
from_el = int(val)
if key == 'to_el':
to_el = int(val)
routes = Route.objects.filter(**kwargs).order_by('-modifiedDT')
if from_el and to_el:
routes = routes[from_el:to_el]
elif from_el:
routes = routes[from_el:]
elif to_el:
routes = routes[:to_el]
res_Dict = {}