Django: How to automatically change a field's value at the time mentioned in the same object?

后端 未结 5 1106
抹茶落季
抹茶落季 2020-12-23 23:01

I am working on a django project for racing event in which a table in the database has three fields.

1)Boolean field to know whether race is active or not

2)

5条回答
  •  無奈伤痛
    2020-12-23 23:25

    You can override the predefined save method like this:

    def save(self, *args, **kwargs):
        if start:
            boolean_field = True
            super(YouModel, self).save(*args, **kwargs)
        else:
            boolean_filed = False
            super(YouModel, self).save(*args, **kwargs)
    

提交回复
热议问题