> Le 30 mai 2017 à 08:54, Priyanka Thakur <priyanka.t...@gmail.com> a écrit :
> 
> I am using Django rest 3.6.2 version .
> 
> The model class is having a ForeignKey relationship as :
> 
> class Deliverable(model.Model):
>         architectureattribute = models.ForeignKey(Architectureattribute, 
> blank=True, null=True)
> 
> 
> 
> class DeliverableSerializer(serializers.ModelSerializer):
>     class Meta:
>          model = Deliverable
>          fields = tuple([getattr(x, 'name') for x in 
> Deliverable._meta.fields])
> 
> 
> In Django Rest , the serializer object is decoded as for the foreign key as:
> 
> architectureattribute = PrimaryKeyRelatedField(allow_null=True, 
> queryset=Architectureattribute.objects.all(), required=False)
> 
> 
> With a put request i am updating only some fields and since I'm doing 
> migration, Database contains null value for the architectureattribute.
> 
> But with "null" value , serializer validation is failing. 
> 
> On debugging I found that the PrimaryKeyRelatedField is not handling the 
> "null" value, even though allow_null property is set. 
> 
> Please explain or guide, as to what I'm doing wrong here . 

Before going further, a few points need to be more clear.
Can you provide the request’s payload you’re sending ?
What’s the exact response message or the traceback ?
Can you print a serializer’s (not your code, but an actual serializer’s 
instance) so we can check what constraints it has ?
Did you try with the latest Django REST framework version ?

Regards,
Xavier Ordoquy,
Linovia.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to