[Answered ]-Django – When fields are flexible at creation time

1👍

You can use dict.get(). dict.get() return the value for key if the key is in the dictionary, else default. If the default is not given(as our case), it defaults to None.

if request.data:
    partners = request.data["partner"]
    for partner in partners:
        MatchingPartner.objects.create(
            matching=matching_instance,
            non_user_nm=partner.get("non_user_nm"),
            non_user_gender=partner.get("non_user_gender"),
        )
👤Mamed

Leave a comment