Search code examples
pythondjangodjango-ormdjango-q

Django: Extracting a `Q` object from a `QuerySet`


I have a Django QuerySet, and I want to get a Q object out of it. (i.e. that holds the exact same query as that queryset.)

Is that possible? And if so, how?


Solution

  • No, but you could create the Q object first, and use that; alternatively, create your query as a dict, and pass that to your filter method and the Q object.