2

I have the following Models in a Django Project:

class Accion(models.Model):
   nombre = models.CharField(max_length=100,blank = True, null=True)

class Proyecto(models.Model):
   titulo = models.CharField(max_length=100,blank = True, null=True)
   acciones = models.ManyToManyField(Accion,blank = True, null=True,related_name="Proyectos")

I need to get all Accion objects related with a list of ids of Proyecto objects in a reversed filter() query. I tried this:

ids_Proyecto=Proyecto.values_list('id').filter(titulo__icontains='ejemplo')
list_acciones=Accion(proyectos__id__in=ids_Proyecto)

But I get the following error: 'proyectos_id_in' is an invalid keyword argument for this function

How can i get the Accion objects queryset? Thankss

4

1 回答 1

3

Change the line to:

list_acciones=Accion.objects.filter(proyectos__id__in=ids_Proyecto)

See Retrieving specific objects with filters for more details on how to use filter queries.

于 2013-10-18T06:19:29.230 回答