fires3as0n
fires3as0n

Reputation: 419

Django all possible Q() arguments?

I am reading Django documentation, particularly about Q() class. It has several sections about it, like: Q() objects and Complex lookups with Q objects
There, authors mention arguments that can be passed to Q(), like

Q(question__startswith='What')

I know that there are other arguments possible, like

Q(name__icontains='What')

This brings me to the conclusion, that a complete list of all available args must exist somewhere, unfortunately, despite that, searching through official documentation or googling lead to nothing

If someone can explain me, what should I do in this situation, it will be much appreciated

*UPD @FamousJameous comment pointed me to the right place, idk if this thread should be kept for dumbs like I am or deleted for uselessness.

Upvotes: 0

Views: 581

Answers (1)

Gytree
Gytree

Reputation: 540

As the documentation said:

A Q() object, like an F object, encapsulates a SQL expression in a Python object that can be used in database-related operations

so the Q objects can receive all the fields of a model field or annotated column. so if you define a model like:

class Home(models.Model):
    address = models.CharField(max_length=255)

You can use:

Home.objects.filter(Q(address="user address"))

so you can use any field from your model with the Q objects. you can also use the all built-in fields lookups and your custom-lookups in your queries.

Upvotes: 1

Related Questions