我有我的模特。py
class Restaurant(models.Model):
name = models.CharField(max_length=100, blank=False)
opening_time = models.TimeField(blank=False)
closing_time = models.TimeField(blank=False)
def __str__(self):
return self.name
@property
def is_open(self):
return True if self.opening_time <= datetime.now().time() < self.closing_time else False
然后,我的serializer.py:
class RestaurantSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Restaurant
fields = ('pk', 'name', 'opening_time', 'closing_time')
如何输入我输入的时间是24小时还是上午和下午。
答案 0 :(得分:1)
您的settings.py
编辑日期时间格式
REST_FRAMEWORK = {
'DATETIME_FORMAT': "%b %d at %I:%M %P"
}