0

I have a field in my model

Step=models.IntegerField()

I call it normally in the template with the following:

{{user.step}}

Now I want this field to automatically increase after every year

What is the best approach here?

1 Answer 1

0

Is it based on some timestamp? like a birth date?

In this case you have few option:

  1. Make it a property and recalculate it before sending data to template

    from dateutil.relativedelta import relativedelta
    
    @property
    def step(self):
        return relativedelta(datetime.now(), self.timestamp).years
    
  2. Make cronjob that will update step field every day using method above

Sign up to request clarification or add additional context in comments.

2 Comments

So I have to install cronjob library right? I was thinking of a way to do it without any third party library
Cron is build into Linux. You should be able to run django command with something like "* * * * * python /path/to/project/manage.py management_command"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.