Hi,
You can use Django annotation feature which will add a field to your
queryset objects and that field can behve like any real field
On Thu, Jun 6, 2019 at 8:22 PM Chetan Ganji wrote:
> Yes Olivier, You are right :P
>
> If I understand the problem correctly this time, you want the field
> ava
Yes Olivier, You are right :P
If I understand the problem correctly this time, you want the field
available on django model, but does not want the python to do the
calculation.
You want the database to compute the value.
If yes, you could use a row level trigger i.e after create and after update
Thanks Chetan for trying to help, but please read carefully the issue, as
you didn't understand what I'm trying to do.
In the meantime, and for the record, I found this, which works for simple
cases. https://github.com/schinckel/django-computed-field
On Thu, 6 Jun 2019 at 14:57, Chetan Ganji wr
I think this would solve your problem. Whatever calculations needs to be
done, you can do it manually before saving the Sales instance.
Preferably after checking if form.is_valid() in case of django and in the
function perform_create() in case of django rest framework.
class Sales(models.Model):
Thanks for the answer. As said, the @property + python method wouldn't work
for my use case, as I need to be able to use the field in the queryset to
filter/order (plus my actual computed field use aggregates expressions).
Cheers,
Olivier
On Thu, 6 Jun 2019 at 12:36, Chetan Ganji wrote:
> I ha
I had a similar need in one of my clients project, I ended up using
@property and a python method.
AFAIK, AnnotationField is absent from django models. If you would like to
write one, below is the material you need to refer.
https://docs.djangoproject.com/en/2.2/howto/custom-model-fields/
Regard
Dear list,
I was wondering whether there's a package or pattern to define annotations
as model fields, so that they could really be used as database-side
computed fields.
Currently, I do something like this (not tested, it's a simplified case):
class SalesManager(models.Manager):
def get_queryse
7 matches
Mail list logo