MyApp\..*create.*\(|MyApp\(
You're looking for locations in your django app where you might create a model object. Now you could just do a search for MyApp.objects.create(
but that only tackles one method of creation. You can also do MyApp.objects.get_or_create
, MyApp.objects.update_or_create
or just MyApp(
model_name = "MyApp"
my_text = """
MyApp.objects.bob(
MyApp.objects.create(
MyApp.objects.get_or_create(
MyApp.objects.update_or_create(
MyApp(fun=true
"""
re.findall(f"{model_name}\..*create.*\(|{model_name}\(", my_text)
#['MyApp.objects.create(',
# 'MyApp.objects.get_or_create(',
# 'MyApp.objects.update_or_create(',
# 'MyApp(']
The top snippet will also work in pycharms Find in Files
so that's also very useful
MyApp # is the name of your model
\. # \. matches the character . literally
.* # .* matches any character (except for line terminators)
create # just a word you expect in the phrase
.*
\( # \( matches the character ( literally
| # OR can match the following
MyApp\("
I really like the site when it comes to working it out https://regex101.com/