D
D
dumahism2019-11-10 21:54:11
Django
dumahism, 2019-11-10 21:54:11

How to select an object in which the field is the beginning of the line?

there is path = name1/qqqq/qq
in the table there is:
name=name1/q
name=name2
you need to extract the object with name=name1/q, because "name1/q" is the beginning of path.
ORM tools.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dumahism, 2019-11-11
@dumahism

so it turned out
Model.objects.annotate(screen_name=V(path, output_field=CharField())).filter(screen_name__startswith=F('name'))

S
Shohruh Shaimardonov, 2019-11-10
@joeberetta

So just break the path into substrings. You can split on the symbol "/" and just throw the desired part of the substring as a parameter in sql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question