Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Field Lookups - startswith


Example

Get all records where firstname starts with the letter "S":

mydata = Member.objects.filter(firstname__startswith='S').values()
Run Example »

Definition and Usage

The startswith lookup is used to get records that starts with a specified value.

The startswith lookup is case sensitive.

For a case insensitive search, use the istartswith lookup.


SQL Equivalent

The SQL equivalent to the example above will be:

WHERE firstname LIKE 'S%';

Syntax

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

fieldname__startswith='value'