def test_regex_substr(self): Alphabet.objects.create(d="The <tag> is there") qs = Alphabet.objects.annotate(d_tag=RegexpSubstr("d", r"<[^>]+>")).filter( d_tag__gt="" ) ab = qs.get() assert ab.d_tag == "<tag>"
def test_regex_substr_field(self): Alphabet.objects.create(d="This is the string", e=r"\bis\b") qs = (Alphabet.objects.annotate( substr=RegexpSubstr("d", F("e"))).filter( substr__gt="").values_list("substr", flat=True)) substr = qs[0] assert substr == "is"
def test_regex_substr_field(self): Alphabet.objects.create(d='This is the string', e=r'\bis\b') qs = (Alphabet.objects.annotate( substr=RegexpSubstr('d', F('e'))).filter( substr__gt='').values_list('substr', flat=True)) substr = qs[0] assert substr == 'is'
def test_regex_substr(self): Alphabet.objects.create(d='The <tag> is there') qs = ( Alphabet.objects.annotate(d_tag=RegexpSubstr('d', r'<[^>]+>')) .filter(d_tag__gt='') ) ab = qs.get() assert ab.d_tag == '<tag>'
def test_regex_substr_filter(self): Author.objects.create(name="Euripides") Author.objects.create(name="Frank Miller") Author.objects.create(name="Sophocles") qs = list( Author.objects.annotate( name_has_space=Length(RegexpSubstr("name", r"\s"))).filter( name_has_space=0).order_by("id").values_list("name", flat=True)) assert qs == ["Euripides", "Sophocles"]
def test_regex_substr_filter(self): Author.objects.create(name="Euripides") Author.objects.create(name="Frank Miller") Author.objects.create(name="Sophocles") qs = list( Author.objects.annotate(name_has_space=Length( RegexpSubstr('name', r'\s')), ).filter( name_has_space=0).order_by('id').values_list('name', flat=True), ) assert qs == ['Euripides', 'Sophocles']