mirror of
https://github.com/django/django.git
synced 2024-11-24 11:48:10 +01:00
Fixed #2458 -- DB API now properly escapes backslashes, so you don't have to double-escape them. Thanks, tom@eggdrop.ch
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3552 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3e22c8ff52
commit
23964a7b9a
1
AUTHORS
1
AUTHORS
@ -125,6 +125,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
|
||||
David Schein
|
||||
sopel
|
||||
Thomas Steinacher <tom@eggdrop.ch>
|
||||
Radek Švarz <http://www.svarz.cz/translate/>
|
||||
Swaroop C H <http://www.swaroopch.info>
|
||||
Aaron Swartz <http://www.aaronsw.com/>
|
||||
|
@ -20,7 +20,7 @@ BLANK_CHOICE_DASH = [("", "---------")]
|
||||
BLANK_CHOICE_NONE = [("", "None")]
|
||||
|
||||
# prepares a value for use in a LIKE query
|
||||
prep_for_like_query = lambda x: str(x).replace("%", "\%").replace("_", "\_")
|
||||
prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
|
||||
|
||||
# returns the <ul> class for a given radio_admin value
|
||||
get_ul_class = lambda x: 'radiolist%s' % ((x == HORIZONTAL) and ' inline' or '')
|
||||
|
@ -15,7 +15,7 @@ class Article(models.Model):
|
||||
def __str__(self):
|
||||
return self.headline
|
||||
|
||||
API_TESTS = """
|
||||
API_TESTS = r"""
|
||||
# Create a couple of Articles.
|
||||
>>> from datetime import datetime
|
||||
>>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26))
|
||||
@ -161,13 +161,14 @@ DoesNotExist: Article matching query does not exist.
|
||||
<Article: Article 1>
|
||||
|
||||
# Underscores and percent signs have special meaning in the underlying
|
||||
# database library, but Django handles the quoting of them automatically.
|
||||
# SQL code, but Django handles the quoting of them automatically.
|
||||
>>> a8 = Article(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20))
|
||||
>>> a8.save()
|
||||
>>> Article.objects.filter(headline__startswith='Article')
|
||||
[<Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>]
|
||||
>>> Article.objects.filter(headline__startswith='Article_')
|
||||
[<Article: Article_ with underscore>]
|
||||
|
||||
>>> a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21))
|
||||
>>> a9.save()
|
||||
>>> Article.objects.filter(headline__startswith='Article')
|
||||
@ -182,4 +183,12 @@ DoesNotExist: Article matching query does not exist.
|
||||
[<Article: Article% with percent sign>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>]
|
||||
>>> Article.objects.exclude(headline="Article 7")
|
||||
[<Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 1>]
|
||||
|
||||
# Backslashes also have special meaning in the underlying SQL code, but Django
|
||||
# automatically quotes them appropriately.
|
||||
>>> a10 = Article(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22))
|
||||
>>> a10.save()
|
||||
>>> Article.objects.filter(headline__contains='\\')
|
||||
[<Article: Article with \ backslash>]
|
||||
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user