@@ -425,9 +425,14 @@ def update(self, instance, validated_data):
425
425
426
426
@transaction .atomic
427
427
def create (self , validated_data ):
428
- partij_uuid = str (validated_data .pop ("partij" ).get ("uuid" ))
429
- validated_data ["partij" ] = Partij .objects .get (uuid = partij_uuid )
428
+ partij = validated_data .pop ("partij" , None )
429
+ if not partij :
430
+ raise serializers .ValidationError (
431
+ {"identificeerde_partij" : _ ("Dit veld is vereist." )},
432
+ code = "required" ,
433
+ )
430
434
435
+ validated_data ["partij" ] = Partij .objects .get (uuid = str (partij .get ("uuid" )))
431
436
return super ().create (validated_data )
432
437
433
438
@@ -721,12 +726,16 @@ def update(self, instance, validated_data):
721
726
if partij_identificatoren :
722
727
partij .partijidentificator_set .all ().delete ()
723
728
for partij_identificator in partij_identificatoren :
724
- partij_identificator ["partij" ] = {"uuid" : str (partij .uuid )}
729
+ partij_identificator ["identificeerde_partij" ] = {
730
+ "uuid" : str (partij .uuid )
731
+ }
725
732
partij_identificator_serializer = PartijIdentificatorSerializer (
726
733
data = partij_identificator
727
734
)
728
735
partij_identificator_serializer .is_valid (raise_exception = True )
729
- partij_identificator_serializer .create (partij_identificator )
736
+ partij_identificator_serializer .create (
737
+ partij_identificator_serializer .validated_data
738
+ )
730
739
731
740
if partij_identificatie :
732
741
serializer_class = self .discriminator .mapping [
@@ -828,12 +837,16 @@ def create(self, validated_data):
828
837
829
838
if partij_identificatoren :
830
839
for partij_identificator in partij_identificatoren :
831
- partij_identificator ["partij" ] = {"uuid" : str (partij .uuid )}
840
+ partij_identificator ["identificeerde_partij" ] = {
841
+ "uuid" : str (partij .uuid )
842
+ }
832
843
partij_identificator_serializer = PartijIdentificatorSerializer (
833
844
data = partij_identificator
834
845
)
835
846
partij_identificator_serializer .is_valid (raise_exception = True )
836
- partij_identificator_serializer .create (partij_identificator )
847
+ partij_identificator_serializer .create (
848
+ partij_identificator_serializer .validated_data
849
+ )
837
850
838
851
return partij
839
852
0 commit comments