Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
DoesNotExist: [Model] matching query does not exist at id (ObjectId)

I am trying to query a unique document using its ObjectId. However the error comes up:

DoesNotExist: Route matching query does not exist

When, upon passing this to my view as request, it prints out the corresponding ObjectId in ObjectId typeform. Therefore there shouldn't be a problem with the line route_test = Route.objects.get(id=_id). I have the following code:

views.py

def update(request):

    if request.method == "POST":

        _id = request.POST.get('_id',ObjectId())
        print(_id)
        route_id = request.POST.get('route_id','')
        geometry = request.POST.get('geometry', '')
        properties = request.POST.get('properties','')

        #r = Route.objects.get(route_id='LTFRB_PUJ2616') --> I cannot use this
                                      #because it has 5 instances (Not Unique)
        #print (r["id"],r["properties"]) 

        test = Route.objects.get(id = ObjectId('587c4c3b203ada19e8e0ecf6'))
        print (test["id"], test["properties"])

        try:
            route_test = Route.objects.get(id=_id)
            print(route_test)
            Route.objects.get(id=_id).update(set__geometry=geometry, set__properties=properties)
            return HttpResponse("Success!")

        except:
            return HttpResponse("Error!")

ajax

 var finishBtn = L.easyButton({
     id:'finish',
     states: [{
              icon:"fa fa-check",
              onClick: function(btn){
                  selectedFeature.editing.disable();
                  layer.closePopup();
                  var editedFeature = selectedFeature.toGeoJSON();
                  alert("Updating:" + editedFeature.route_id);

                  $.ajax({
                     url: "/update/",
                     data: {id:editedFeature.id,
                            route_id: JSON.stringify(editedFeature.route_id),
                            geometry: JSON.stringify(editedFeature.geometry),
                            properties: JSON.stringify(editedFeature.properties)
                         }, 
                     type: 'POST'     
            });
 }

model.py

from __future__ import unicode_literals

from mongoengine import *

class Route(Document):
    type = StringField(required=True)
    route_id = StringField(required=True)
    geometry = LineStringField()
    properties = DictField()

    meta = {'collection':'routes'}

What should be done? Even the line test = Route.objects.get(id = ObjectId('587c4c3b203ada19e8e0ecf6')) where I directly supplied the incoming _id has the same error...

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda