如何每周自动将数据添加到数据库?

时间:2019-04-12 12:09:41

标签: python django

我想在每个周末将“ Weekstaat”自动添加到数据库中。

型号:

class Weekstaat(models.Model):
    id = models.AutoField(primary_key=True, null=False, blank=False)
    #status = models.ForeignKey(Status, null=False, blank=False, default=1,on_delete=models.CASCADE)
    jaar = models.ForeignKey(Jaar, default=datetime.now().year, null=False, blank=False,on_delete=models.CASCADE)
    week = models.ForeignKey(Week, default=date.today().isocalendar()[1], null=False, blank=False,on_delete=models.CASCADE)
    werknemer = models.ForeignKey(User, related_name='weekstaat_werknemer', null=False, blank=False, default=1,on_delete=models.CASCADE)
    maandag = models.FloatField(null=True, blank=True)
    dinsdag = models.FloatField(null=True, blank=True)
    woensdag = models.FloatField(null=True, blank=True)
    donderdag = models.FloatField(null=True, blank=True)
    vrijdag = models.FloatField(null=True, blank=True)
    zaterdag = models.FloatField(null=True, blank=True)
    zondag = models.FloatField(null=True, blank=True)

    def __str__(self):
        return str(self.jaar) + ' week ' + str(self.week) + str(self.werknemer)

视图:

class weekstaat(generic.ListView):
    model = Weekstaat
    context_object_name = 'Weekstaten'
    template_name = 'weekstaat/index.html'

1 个答案:

答案 0 :(得分:0)

您可以为此编写CRON JOBS,这是一些Django的CRON软件包 Django-CRON

https://djangopackages.org/grids/g/cron/