0.1.9
edit route fix
This commit is contained in:
@@ -33,7 +33,13 @@ def edit_route_ajax(request):
|
|||||||
|
|
||||||
route = Route.objects.get(id=data['route_id'])
|
route = Route.objects.get(id=data['route_id'])
|
||||||
|
|
||||||
form = CreateRouteForm(instance=route)
|
form = RouteForm(instance=route)
|
||||||
|
route_address_points_Dict = route.get_address_points()
|
||||||
|
form.initial.update({
|
||||||
|
'from_address_point_txt': route_address_points_Dict['from_address_point_txt'],
|
||||||
|
'to_address_point_txt': route_address_points_Dict['to_address_point_txt'],
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
Dict = {
|
Dict = {
|
||||||
'form': form
|
'form': form
|
||||||
|
|||||||
@@ -65,4 +65,44 @@ class Route(BaseModel):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _(u'Маршрут')
|
verbose_name = _(u'Маршрут')
|
||||||
verbose_name_plural = _(u'Маршруты')
|
verbose_name_plural = _(u'Маршруты')
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|
||||||
|
def get_address_points(self):
|
||||||
|
from ReferenceDataApp.models import Airport, City
|
||||||
|
|
||||||
|
try:
|
||||||
|
if self.type_transport == 'avia':
|
||||||
|
from_address_point_objs = Airport.objects.filter(id=self.from_address_point)
|
||||||
|
from_address_point_Dict = from_address_point_objs.values(
|
||||||
|
'id', 'name', 'iata_code', 'city__name', 'city__country__name')[0]
|
||||||
|
to_address_point_objs = Airport.objects.filter(id=self.to_address_point)
|
||||||
|
to_address_point_Dict = to_address_point_objs.values(
|
||||||
|
'id', 'name', 'iata_code', 'city__name', 'city__country__name')[0]
|
||||||
|
|
||||||
|
from_address_point_txt = f'{from_address_point_Dict["iata_code"]} - {from_address_point_Dict["name"]}'
|
||||||
|
to_address_point_txt = f'{to_address_point_Dict["iata_code"]} - {to_address_point_Dict["name"]}'
|
||||||
|
else:
|
||||||
|
from_address_point_objs = City.objects.filter(id=self.from_address_point)
|
||||||
|
from_address_point_Dict = from_address_point_objs.values(
|
||||||
|
'id', 'name', 'country__name')[0]
|
||||||
|
to_address_point_objs = City.objects.filter(id=self.to_address_point)
|
||||||
|
to_address_point_Dict = to_address_point_objs.values(
|
||||||
|
'id', 'name', 'country__name')[0]
|
||||||
|
|
||||||
|
from_address_point_txt = f'{from_address_point_Dict["country__name"]} / {from_address_point_Dict["name"]}'
|
||||||
|
to_address_point_txt = f'{to_address_point_Dict["country__name"]} / {to_address_point_Dict["name"]}'
|
||||||
|
|
||||||
|
return {
|
||||||
|
'from_address_point_obj': from_address_point_objs[0],
|
||||||
|
'from_address_point_Dict': from_address_point_Dict,
|
||||||
|
'from_address_point_txt': from_address_point_txt,
|
||||||
|
|
||||||
|
'to_address_point_obj': to_address_point_objs[0],
|
||||||
|
'to_address_point_Dict': to_address_point_Dict,
|
||||||
|
'to_address_point_txt': to_address_point_txt,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f'get_address_points Error = {str(e)}')
|
||||||
|
return None
|
||||||
Reference in New Issue
Block a user