I'm trying to update all urls in my query by using django's update
and Replace
function using regex.
Here's what I've tried so far but it seems like django's Value
expression did not recognize my regex.
from django.db.models import Value
from django.db.models.functions import Replace
Foo.objects.filter(
some_url__iregex=r'^/some-link/d+/').update(
some_url=Replace(
'some_url', Value(r'^/some-link/d+/'),
Value('/some-link/')))
My goal is to remove all numbers after /some-link/
(e.g. /some-link/55/test
to just /some-link/test
)
question from:
https://stackoverflow.com/questions/65838311/how-can-i-use-regex-in-djangos-replace-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…