"DoesNotExist 오류"를 파악하는 데 문제가 있습니다. 무응답 결과를 관리하는 올바른 방법을 찾으려고 노력했지만 "DoesNotExist"또는 "개체에 DoestNotExists 속성이 없습니다"문제가 계속 발생합니다.
from django.http import HttpResponse
from django.contrib.sites.models import Site
from django.utils import simplejson
from vehicles.models import *
from gpstracking.models import *
def request_statuses(request):
data = []
vehicles = Vehicle.objects.filter()
Vehicle.vehicledevice_
for vehicle in vehicles:
try:
vehicledevice = vehicle.vehicledevice_set.get(is_joined__exact = True)
imei = vehicledevice.device.imei
try:
lastposition = vehicledevice.device.devicetrack_set.latest('date_time_process')
altitude = lastposition.altitude
latitude = lastposition.latitude
longitude = lastposition.longitude
date_time_process = lastposition.date_time_process.strftime("%Y-%m-%d %H:%M:%S"),
date_time_created = lastposition.created.strftime("%Y-%m-%d %H:%M:%S")
except Vehicle.vehicledevice.device.DoesNotExist:
lastposition = None
altitude = None
latitude = None
longitude = None
date_time_process = None
date_time_created = None
except Vehicle.DoesNotExist:
vehicledevice = None
imei = ''
item = [
vehicle.vehicle_type.name,
imei,
altitude,
"Lat %s Lng %s" % (latitude, longitude),
date_time_process,
date_time_created,
'',
''
]
data.append(item)
statuses = {
"sEcho": 1,
"iTotalRecords": vehicles.count(),
"iTotalDisplayRecords": vehicles.count(),
"aaData": data
}
json = simplejson.dumps(statuses)
return HttpResponse(json, mimetype='application/json')