I have a model that includes a @property
that I want included when I do things like
vals = MyModel.objects.values()
Another S/O post suggests the way to do this is by overriding the get_queryset
method of a manager class, augmented with a call to annotate(xtra_field=...)
.
The problem is I can find no example of how to do this with a model property. I have tried things like
super(SuperClass, self).get_queryset().annotate(xtra_fld=self.model.xtra_prop)
and numerous variations thereof, none of which work.
The question, I think is What should the RHS of the annotation argument(s) be?
(And, yes, I know there are other, clunkier ways to do this, like iterating over what values()
returns and adding the property as I go. Just not a very elegant (or even django) solution, to me.
@property
, since properties are at the Python level. The database does not know anything about the properties. – OfeliaHand
example in the docu. – Moir