J
J
Jekson2020-05-05 10:50:55
Django
Jekson, 2020-05-05 10:50:55

Schedule background task for django model?

There is a model in which, depending on the current time, you need to update one status field

class Rfis(models.Model):
    RFI_STATUS = (
                    ("Created", "Created"),
                    ("Opened", "Opened"),
                    ("Issued", "Issued")
                 )
    rfi_status = models.CharField(max_length=50, choices=RFI_STATUS, default="Created")
    rfiid = models.CharField(max_length=4, primary_key=True)
    active = models.BooleanField(default=True)
    issue_datetime = models.DateTimeField(blank=True, null=True)
    open_datetime = models.DateTimeField(blank=True, null=True)
    close_datetime = models.DateTimeField(blank=True, null=True)
    timestamp = models.DateTimeField(auto_now_add=True)

logic example:
if current time >= issue_datetime then status = Issued.

What is the easiest way to implement such a task? I know about Celery but wouldn't it be overkill for such a simple task. Maybe there are more relevant ways?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-05-05
@Lepilov

You can write a management command and run it with cron . Although I would look in the direction of changing the logic so that I don’t have to change the data on the timer at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question