[Fixed]-Django: Filtering a model that contains a field that stores Regex

20👍

Use the Django __contains method.

So for your query:

Sys_team.objects.filter(hostname__contains='.amgr.')

__contains is Django ORM’s equivalent to SQL’s LIKE keyword.

Here’s the docs:

https://docs.djangoproject.com/en/dev/topics/db/queries/#escaping-percent-signs-and-underscores-in-like-statements

Leave a comment