我正在发布这样的休息请求:
{title:some title, recurring:true, day:Wednesday, time:12:30, description:some text}
我没有通过日期,因为该事件正在重复发生并且该值应该为空。服务器响应是:
{"date": ["This field cannot be blank."]}
这是相关的python代码:
class Event(models.Model):
title = models.CharField(max_length=200)
recurring = models.BooleanField()
day = models.CharField(max_length=20, blank=True)
date = models.DateField(null=True)
time = models.TimeField()
description = models.CharField(max_length=500)
venue = models.CharField(max_length=200, blank=True)
venueAddress = models.CharField(max_length=200, blank=True)
venueCity = models.CharField(max_length=200, blank=True)
class EventSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Event
class EventViewSet(viewsets.ModelViewSet):
queryset = Event.objects.all()
serializer_class = EventSerializer
我不完全确定消息来自哪里。我的模型定义正确吗?我的序列化程序需要额外的工作吗?