I am starting to use Django and I have this code in my app:
filtro = "marca:samsung_modelo:s3"
mifiltro = filtro.split('_')
cadena = '0'
for caracteristica in mifiltro:
if not cadena == '0':
cadena += ", "
elif cadena == '0':
cadena = ''
aux = caracteristica.split(':')
cadena += aux[0] + "='" + aux[1] + "'"
Then cadena
is:
marca='samsung',modelo='s3'
I want use this variable as filter like this:
productos = Producto.objects.filter(cadena)
But I get the error "too many values to unpack".
If I write in my code:
productos = Producto.objects.filter(marca='samsung',modelo='s3')
It works fine. Can I use a string to filter an object?