Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
How to set the value of a model field by performing an equation between other model fields

I want to set the value of a model field by performing an equation between other model fields. Here's my model:

class Current(models.Model):
    time = models.IntegerField(default=0)
    post_score = models.ForeignKey(PostScore, blank=True, null=True)
    comment_score = models.ForeignKey(CommentScore, blank=True, null=True)

Say I want to create a new field called rate, which is calculated by:

(post_score + comment_score) / time

Is this possible?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Something like this:

models.py

class Current(models.Model):
    ....

    def get_current_rate(self):
        return (self.post_score + self.comment_score) / self.time

In views.py:

from mymodels import Current

def someview():
    ....
    rate = Current.get_current_rate()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!