Francisco Ghelfi
Francisco Ghelfi

Reputation: 962

Django foreignkey field filtering problem

I´m trying to filter a queryset with a ForeignKey field but I get the following error:

Cannot resolve keyword 'workflowcontenidos' into field. Choices are: 
categoria_producto, descripcion_brief, descripcion_long, estatus_contenido, 
estatus_contenido_id, foto_1, foto_2, id, perfil_cliente, productosbase, usos, 
video

My models are:

 class WorkflowContenidos(models.Model):
    estatus = models.CharField(max_length=200, help_text="Estatus de contenido", blank=False, null=True)

    def __str__(self):
        return str(self.estatus)


class Categorias_Producto(models.Model):
    categoria_producto = models.CharField(max_length=50, help_text="Catergoría de producto", unique=True, blank=False, null=True)
    descripcion_brief = models.TextField(max_length=200, help_text="Descripción resumida", blank=True, null=True)
    descripcion_long = models.TextField(max_length=500, help_text="Descripción extendida", blank=True)
    usos = models.CharField(max_length=200, help_text="Usos (separados por comas)", blank=True, null=True)
    foto_2 = models.ImageField(upload_to='', default="", blank=False, null=False)
    foto_1 = models.ImageField(upload_to='', default="", blank=False, null=False)
    video = models.URLField("Link brand video", max_length=128, blank=True, null=True)
    perfil_cliente = models.CharField(max_length=200, help_text="Perfil de cliente", blank=True, null=True)
    estatus_contenido = models.ForeignKey("WorkflowContenidos", help_text="Estatus del contenido", blank=True, null=True, on_delete=models.CASCADE)

    def __str__(self):
        return str(self.categoria_producto)

The "estatus" values in the WorkflowContenidos model are:

Incompleto
Revisión
Aprobado

The view:

def WorkflowContenidosView(request):
    lista_visualizacion = Categorias_Producto.objects.filter(workflowcontenidos__estatus='Incompleto')

    return render(request, 'catalog/content-workflow.html', {
        'lista_visualizacion': lista_visualizacion
    })

Upvotes: 0

Views: 44

Answers (1)

Danil
Danil

Reputation: 5171

lista_visualizacion = Categorias_Producto.objects.filter(estatus_contenido__estatus='Incompleto')

Upvotes: 1

Related Questions