No.
Usually, you would try to keep all of your filtering in the managers module, 
and then you would be able to limit your refactoring of filters in that file.
You could try using *args and **kwargs syntax, but that would make it difficult 
to maintain.
I suppose you could functions in SQLAlchemy, and if you really wanted functions 
in Django, you could make them yourself.

I actually like the Django syntax.  It's very easy to follow.  You can also use 
the __ for related fields.
Questions.objects.filter(something__related_something__related_something_else__lower__contains="what")


-----Original Message-----
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of megaman
Sent: Tuesday, October 9, 2018 10:03 AM
To: Django users
Subject: Alternatives to using __contains?

I’m pretty new to Django. I have just learnt that could filter a query set this 
way: 

Questions.objects.filter(question_text__contains=‘what’)

This kind of scares me a little because the filter “contains” is actually part 
of the field name. And I guess there are other operators appended to a field 
with the same __operation pattern.

Wouldn’t this make refactoring tricky? Even renaming the field name has to be 
done carefully. In my mind, this feels messy. 

Is there an alternative to doing this? Something like:
Questions.objects.filter(question_text.contains=‘what’)
Or using “contains” as a function?

Basically, can I do the same thing without adding “magic strings” to field 
names?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3f7194e9-b600-4a14-be1e-83f0cb35dac6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d461d8c15ebb4644a9e909e6295687ff%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to