I have routes associated with locations, I want that when I type ' link ' I return all the locations with the path of id 11 but if you have two or more I get the error: "MultipleObjectsReturned at / rest / Location / 11 /
get () returned more than one Location - it returned 2! "
My models is as follows:
class Ubicacion(models.Model):
nombre = models.CharField(max_length=200)
lat = models.CharField(max_length=50)
lng = models.CharField(max_length=50)
fecha = models.DateTimeField(auto_now_add=True)
docfile = models.FileField(upload_to='')
user = models.ForeignKey(User,on_delete=models.PROTECT)
descripcion = models.CharField(max_length=500)
TextoParaAudio = models.CharField(max_length=100)
Ruta = models.ForeignKey(Ruta,on_delete=models.PROTECT)
My viewsets:
class UbicacionViewSetById(viewsets.ModelViewSet):
serializer_class = UbicacionSerializer
def get_queryset(self):
id = self.kwargs['id']
return Ubicacion.objects.filter(Ruta=id).order_by('id')
my urls:
router.register(r'UbicacionById',UbicacionViewSetById.get_queryset,base_name="UbicacionById")
urlpatterns=[
url(r'^admin/Rutas/ubicacion/add/', include("Rutas.urls")),
url(r'^admin/', admin.site.urls),
url(r'^rest/', include(router.urls)),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Thank you very much!