On Thu, 2009-01-29 at 18:47 +0000, Adam Stein wrote: > According to the docs, when using 'contains' in filter() a percent sign > or underscore is automatically escaped. However, in my case I want the > resulting SQL to use the percent sign. > > I know 'contains' will fill in the outside percent signs, but it escapes > the percent sign in my string. So that calling: > > Entry.objects.filter(headline__contains='a%b') > > will result in: > > SELECT ... WHERE headline LIKE '%a\%b%';
Because the "contains" lookup type is used to look for string containment, not as a proxy for SQL. We deliberately try to not leak the underlying SQL abstraction (the storage backend may not even be SQL, after all). > > but I want it to be this instead: > > SELECT ... WHERE headline LIKE '%a%b%'; > > This there an easy way to do this? > > I could use regexp, but I didn't want people to know that they would > have to use "a.*b" instead of "a*b", just trying to make it simplier for > myself and the people using the system. Well, the regexp lookup type is for this purpose, so it's the right tool to use at the code level. The point about the user-interface is well taken, but it doesn't have to be a transparent pass-through. What I would suggest is converting your value by doing using value = value.replace('%', '.*') at some point. If these values are coming in through a form field, a custom cleaning method for the form field would be a nice level to this at, for example. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---