我有以下资源,并且在我的entrepreneru资源中存在以下字段
我使用字段只获取项目和project_url这很好但是当我尝试使用PATCH更新时,我收到错误消息
" error_message":"列'活动'不能为空"
class EntrepreneurResource(ModelResource):
founders = fields.ToManyField(FounderResource, 'founders_set', null=True, blank=True, full=True)
class Meta:
queryset = EntrepreneurProfile.objects.all()
list_allowed_methods = [] # Block list view
detail_allowed_methods = ['get', 'patch']
fields = ['project', 'project_url']
authorization = Authorization()
class UserResource(ModelResource):
entrepreneur = fields.ToOneField(EntrepreneurResource, 'entrepreneurprofile', null=True, blank=True, full=True)
class Meta:
queryset = User.objects.all()
fields = ['first_name', 'last_name', 'email', 'role']
list_allowed_methods = [] # Block list view
detail_allowed_methods = ['get', 'patch']
#authentication = SessionAuthentication()
authorization = Authorization()
如何解决这个问题?
更新1
class EntrepreneurProfile(models.Model):
user = models.OneToOneField(User, primary_key=True)
project = models.CharField(max_length=512, blank=False)
activity = models.ForeignKey(FormLabelOptions,blank=False, related_name='activity')
project_url = models.URLField()
更新2
$http({
method: 'PATCH',
url: '/api/v1/user/12/',
headers: {'Content-Type': 'application/json'},
data: data
});
答案 0 :(得分:0)
这是一个DB / ORM问题,您需要更新模型并使活动字段可选。
activity = models.ForeignKey(FormLabelOptions,blank=False, null=True, related_name='activity')
不要忘记运行迁移来更新数据库架构。