add route to edit_route
This commit is contained in:
SDE
2023-08-01 19:36:53 +03:00
parent b7e01aa6bc
commit d4c123a775
2 changed files with 11 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ from .js_views import *
urlpatterns = [
path('create_or_change_route/', create_or_change_route_ajax, name='create_or_change_route_ajax'),
path('create_or_change_route/<int:route_id>/', create_or_change_route_ajax, name='change_route_ajax'),
path('edit_route/', edit_route_ajax, name='edit_route_ajax'),
path('get_routes/', get_routes_ajax, name='get_routes_ajax'),

View File

@@ -177,7 +177,7 @@ def get_routes_ajax(request):
def create_or_change_route_ajax(request):
def create_or_change_route_ajax(request, route_id):
if request.method != 'POST':
raise Http404
@@ -186,7 +186,15 @@ def create_or_change_route_ajax(request):
data = request.POST
form = RouteForm(data)
route = None
if route_id:
route = Route.objects.get(id=route_id)
if route:
form = RouteForm(data, instance=route)
else:
form = RouteForm(data)
if not form.is_valid():
form.initial = form.cleaned_data
Dict = {'form': form}