我正在使用 djangorestframework-bulk 来执行批量更新,但遵循文档DRF-Bulk,但对我而言,更新没有用。.
它说,
File "/webapps/env_apibot/local/lib/python2.7/site-packages/rest_framework_bulk/drf3/serializers.py", line 43, in <dictcomp>
for i in all_validated_data
KeyError: 'my_pk'
我的配置是
views.py
class MymodelBulkViewSet(BulkModelViewSet):
model = Mymodel
queryset = Mymodel.objects.all()
serializer_class = MymodelBulkSerializer
serializers.py
class MymodelBulkSerializer(BulkSerializerMixin):
class Meta:
model = Mymodel
list_serializer_class = BulkListSerializer
update_lookup_field = 'my_pk'
models.py
class BillingItem(models.Model):
my_pk = models.AutoField(max_length=11, primary_key=True)
class Meta:
managed = False
但它会引发400错误,并指出未找到关键错误my_pk
。
drf版本3.3.2
Django 1.8.9
答案 0 :(得分:0)
我通过长期的研究解决了这个问题,终于找到了自己。
我尝试覆盖BulkListSerializer,现在它的工作正常,而无需进行任何更改。.我终于经历了BulkSerializerMixin
,BulkListSerializer
的重复,并尝试从中导入它,>
from rest_framework_bulk import BulkSerializerMixin, BulkListSerializer
但实际上它应该来自
from rest_framework_bulk.drf3.serializers import BulkSerializerMixin, BulkListSerializer