Fixed #16731 -- Made pattern lookups work properly with F() expressions

See https://code.djangoproject.com/ticket/16731#comment:11
What I wanted to point out (as mjtamlyn suggested) is that the generated queries for `Foo.objects.filter(bar__contains='baz')` will be more complex than expected as the SQL contains 3 nested `REPLACE` calls, because we have to escape special characters. People might be suprised when seeing such queries (e.g. in the debug toolbar).