Open danilke opened 7 years ago
@danilke Hello! Could you please provide more information? I'm intrested in the samples of serializer's code and the samples of data which you send.
Thank you for so fast feedback! Looks like problem is in my low skill in django, because I have tried to save object from console with UserSerializer, and it went fine.
models.py
class Profile(models.Model):
user = models.OneToOneField(User)
city = models.CharField(max_length=50, blank=True, default='')
phone = models.CharField(max_length=50, blank=True, default='')
serializers.py
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = ('pk', 'city', 'phone',)
class UserSerializer(WritableNestedModelSerializer):
profile = ProfileSerializer(allow_null=True, many=False)
class Meta:
model = User
fields = (
'pk',
'url',
'username',
'email',
'groups',
'profile',
)
Where can be problem? One more tine thanks a lot!
Hm, I was trying to send data from "browsable api" in DRF, and its went wrong, but when I've sended json from postman, was saved without any error :) Thank you for nice library :) It saved me a lot of time!
Same problem, when using multipart formatted data, MultiValueDictKeyError
will be raised.
Some MultiValueDict data like this:
data = {
'a.title': 'xxxxx',
'a.desc': 'vvvvvv'
}
I'm hitting this issue in my code
drf_writable_nested/mixins.py", line 122, in update_or_create_reverse_relations
related_data = self.initial_data[field_name]
MultiValueDictKeyError: "'offices'"
As @rainyx mentioned, this seems to happen with multipart form data.
I'm sending a partial update with the body:
------WebKitFormBoundaryBxUozciZvqZAB7cj
Content-Disposition: form-data; name="org_image"; filename="Group.png"
Content-Type: image/png
------WebKitFormBoundaryBxUozciZvqZAB7cj--
In my serializer, however, I get extra validated_data
:
{ 'org_image': <InMemoryUploadedFile: Group.png (image/png)>, 'offices': [] }
(offices is a writable nested ManyToMany with a standard serializer)
@d3dc Hello! Can you check your issue with v0.4.3?
is it fixed?
this can be closed based on https://github.com/beda-software/drf-writable-nested/pull/42#issuecomment-400545941
Hi, got problem with nested serializer: On request POST: