[Django]-Calling filter with a variable for field name

85👍

Playlist.objects.filter(**{field_name: v})

👤nisc

10👍

To use field name string with icontains.

Try this

field_name = 'video'
field_name_icontains = field_name + '__icontains'
Playlist.objects.filter(**{field_name_icontains: v})

Leave a comment