Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Field Lookups - contains


Example

Get all records that have the value "bias" in the firstname column:

mydata = Member.objects.filter(firstname__contains='bias').values()
Run Example »

Definition and Usage

The contains lookup is used to get records that contains a specified value.

The contains lookup is case sensitive.

For a case insensitive search, use the icontains lookup.


SQL Equivalent

The SQL equivalent to the example above will be:

WHERE firstname LIKE '%bias%';

Syntax

All Field lookup keywords must be specified with the fieldname, followed by two(!) underscore characters __ and the keyword:

fieldname__contains='value'