﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30061	annotate boolean from a Q object	Ryan Hiebert	nobody	"I think that I saw something about this on the Django-Developers mailing list years ago, but I cannot find the reference, unfortunately.

I have on several occasions needed to annotate a boolean. The way that I have found to do this is to use a conditional expression, but it seems awfully noisy to my eyes. It seems like it might be better to allow directly annotating Q objects, or perhaps providing a simple wrapper to convert a Q object into a boolean field expression.

For example, instead of this:

{{{#!python
notes = notes.filter(user=self.user).annotate(
    is_author=Case(
        When(author_id=self.request.user.id, then=True),
        default=Value(False),
        output_field=BooleanField(),
    ),
)
}}}

I think that there's a good case to be made that this should be possible:

{{{#!python
notes = notes.filter(user=self.user).annotate(
    is_author=Q(author_id=self.request.user.id),
)
}}}

Or if we really can't have the `Q` object doing double duty, we could wrap that Q object in some expression constructor. I didn't provide an example, because I couldn't think of a great and obvious name for such a constructor."	New feature	closed	Database layer (models, ORM)	dev	Normal	duplicate			Accepted	0	0	0	0	0	0
