每年为所有用户重置模型中的值 - Django



我正在开发一个跟踪员工假期的 Django 应用程序。我不确定我将如何在每年的特定日期重置假期。对于如何做到这一点,是否有任何已知的解决方案/库?

class User(models.Model):
avatar = models.ImageField(
    default='images/avatars/profile.png',
    upload_to=user_directory_path)
name = models.CharField(max_length=100)
title = models.CharField(max_length=200, default="Employee")
email = models.EmailField(max_length=254)
present = models.BooleanField(default=False)
code = models.CharField(max_length=4, unique=True)
date_created = models.DateTimeField(auto_now_add=True)
date_clocked = models.DateTimeField(default=timezone.now)
total_holiday = models.DecimalField(
    default=28.0, decimal_places=1, max_digits=4)
holiday_remaining = models.DecimalField(
    default=28.0, decimal_places=1, max_digits=4)

我的模型如上所示,我需要在每年管理员用户定义的日期重置remaining_holiday字段。

在你的

主机中设置 crontab,或者使用一个等效的 django 插件,比如这个:https://github.com/kraiz/django-crontab

最新更新