首页 > 解决方案 > 插入几个小时的条件

问题描述

晚上好,你能帮我看看如何设置一个条件,以便出现一条消息说你不能花一个小时,因为它已经很忙了吗?,我目前有这个:

class reserva (models.Model):

     _name='gimnasio.reserva'

     tipo_reserva=fields.Selection([('clase','Clase'),('evaluacion','Evaluacion')])

     fecha_reserva=fields.Date()

     start_time=fields.Float()

     end_time=fields.Float()

     def fecha(self):

          if self.star_time==self.star_time:

               raise validationError('the hour is busy')

标签: pythonodoo

解决方案


I have another question for you. you know how to configure Datetime only for hour and minutes because I only need hour and minutes but not the date.

仅将日期时间配置为小时和分钟。


time = fields.Datetime("time")
custom_time = fields.Char('my_custome_time')
    @api.onchange('time')
    def _get_time(self):
        if self.time:
            for rec in self:
                # datetime value is a string like 'YYYY-mm-dd HH:MM:SS' 
                # so just extract string from position 11 to 16
                _time = self.time[11:16]
                self.custom_time = _time
                rec.custom_time = self.custom_time


推荐阅读