Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django models 使用外键在资源中使用Tastypie更新_Django Models_Foreign Keys_Tastypie - Fatal编程技术网

Django models 使用外键在资源中使用Tastypie更新

Django models 使用外键在资源中使用Tastypie更新,django-models,foreign-keys,tastypie,Django Models,Foreign Keys,Tastypie,外键约束中涉及的资源有问题(不支持**或pow()的操作数类型:'Decimal'和'NoneType')。下面是一段代码(联系人属于部门和客户): 当我尝试更新一个部门时,我没有任何问题。我是这样做的: curl -v -XPATCH -H "Content-Type:application/json" -d "{\"name\": \"Sales\"}" "http://localhost:8000/api/v1/department/1/" 但是当我尝试在其他资源中做同样的事情时 cur

外键约束中涉及的资源有问题(不支持**或pow()的操作数类型:'Decimal'和'NoneType')。下面是一段代码(联系人属于部门和客户):

当我尝试更新一个部门时,我没有任何问题。我是这样做的:

curl -v -XPATCH -H "Content-Type:application/json" -d "{\"name\": \"Sales\"}" "http://localhost:8000/api/v1/department/1/"
但是当我尝试在其他资源中做同样的事情时

curl -v -X PATCH -H "Content-Type:application/json" -d "{\"name\": \"XYZ\"}" "http://localhost:8000/api/v1/client/1/"
返回以下错误:

"error_message": "unsupported operand type(s) for ** or pow(): 'Decimal' and NoneType'"
"traceback": "Traceback (most recent call last):
File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 192, in wrapper\n    response = callback(request, *args, **kwargs)
File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 406, in dispatch_detail\n    return self.dispatch('detail', request, **kwargs)
File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 427, in dispatch\n    response = method(request, **kwargs)
File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 1332, in patch_detail\n    self.update_in_place(request, bundle, deserialized)
File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 1346, in update_in_place\n    return self.obj_update(original_bundle, request=request, pk=original_bundle.obj.pk)
File \"C:\\Python27\\lib\\site-packages\\tastypie\\resources.py\", line 1824, in obj_update\n    bundle.obj.save()
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\base.py\", line 463, in save\n    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\base.py\", line 529, in save_base\n    rows = manager.using(using).filter(pk=pk_val)._update(values)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\query.py\", line 557, in _update\n    return query.get_compiler(self.db).execute_sql(None)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\sql\\compiler.py\", line 986, in execute_sql\n    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\sql\\compiler.py\", line 808, in execute_sql\n    sql, params = self.as_sql()
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\sql\\compiler.py\", line 951, in as_sql\n    val = field.get_db_prep_save(val, connection=self.connection)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\models\\fields\\__init__.py\", line 874, in get_db_prep_save\n    self.max_digits, self.decimal_places)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\backends\\__init__.py\", line 809, in value_to_db_decimal\n    return util.format_number(value, max_digits, decimal_places)
File \"C:\\Python27\\lib\\site-packages\\django\\db\\backends\\util.py\", line 149, in format_number\n    return u'%s' % str(value.quantize(decimal.Decimal(\".1\") ** decimal_places, context=context))
TypeError: unsupported operand type(s) for ** or pow(): 'Decimal' and 'NoneType'\n"}* Closing connection #0

返回

The 'department' field has was given data that was not a URI, not a dictionary-alike and does not have a 'pk' attribute: <Bundle for obj: 'Department object' and with data: '{'id': u'1', 'name': u'Sales', 'resource_uri': '/api/v1/department/1/'}'>.* Closing connection #0
为“department”字段提供的数据不是URI,也不是类似于字典的数据,并且没有“pk”属性:.*正在关闭连接#0
我想外键的定义有问题,但我不知道是什么。当我做手术时,一切都很好。我的定义有什么错?多谢各位

curl -v -X PATCH -H "Content-Type:application/json" -d "{\"name\": \"ZZZZ\"}" "http://localhost:8000/api/v1/contact/1/"
The 'department' field has was given data that was not a URI, not a dictionary-alike and does not have a 'pk' attribute: <Bundle for obj: 'Department object' and with data: '{'id': u'1', 'name': u'Sales', 'resource_uri': '/api/v1/department/1/'}'>.* Closing connection #0