Beispiel #1
0
 def test_regex_replace_filter_backref(self):
     Author.objects.create(name="Charles Dickens")
     Author.objects.create(name="Roald Dahl")
     qs = (Author.objects.annotate(surname_first=RegexpReplace(
         'name', r'^(.*) (.*)$', r'\2, \1'), ).order_by('surname_first'))
     assert qs[0].name == "Roald Dahl"
     assert qs[1].name == "Charles Dickens"
Beispiel #2
0
 def test_regex_replace_filter_backref(self):
     Author.objects.create(name="Charles Dickens")
     Author.objects.create(name="Roald Dahl")
     qs = Author.objects.annotate(surname_first=RegexpReplace(
         "name", r"^(.*) (.*)$", r"\2, \1")).order_by("surname_first")
     assert qs[0].name == "Roald Dahl"
     assert qs[1].name == "Charles Dickens"
 def test_regex_replace_update_expressions(self):
     Alphabet.objects.create(d="I'm feeling sad")
     n = Alphabet.objects.update(
         d=RegexpReplace("d", Value(r"\bsad\b"), Value("happy")))
     assert n == 1
     ab = Alphabet.objects.get()
     assert ab.d == "I'm feeling happy"
Beispiel #4
0
 def test_regex_replace_update_groups(self):
     Alphabet.objects.create(d="A,,List,with,,empty,,,,strings, ")
     n = Alphabet.objects.update(d=RegexpReplace('d', r',{2,}', ','))
     assert n == 1
     ab = Alphabet.objects.get()
     assert ab.d == "A,List,with,empty,strings, "
Beispiel #5
0
 def test_regex_replace_update(self):
     Alphabet.objects.create(d="I'm feeling sad")
     n = Alphabet.objects.update(d=RegexpReplace('d', r'\bsad\b', 'happy'))
     assert n == 1
     ab = Alphabet.objects.get()
     assert ab.d == "I'm feeling happy"