Skip to content
Advertisement

How can I get a value from other model, based in other value from that same other model?

How can I get the proper “sumvalue” in the example? (which I only know how to represent in SQL):

JavaScript

Advertisement

Answer

In your case, c is not a field, but a property.

You can call it on an instance:

JavaScript

Now for what you’re trying to do, I really recommand you use annotate.

JavaScript

You then have an additional field in your query called sum_a_b.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement