pythondjangomodel

Django model filter for string


I have table which has string such as

id | url
1  | /myapi/1241/
2  | /myapi/
3  | /myapi/1423/
4  | /myapi/

Now I want to filter them like this below

myModel.Objects.filter(url="/myapi/****/")

Is it possible , or is there any method to do this?


Solution

  • Filter with the __regex lookup [Django-doc]:

    MyModel.objects.filter(url__regex=r'/myapi/\d+/')