def create(self, validated_data): committees = validated_data.pop('committeepriority_set') application = CommitteeApplication(**validated_data) try: application.clean() except DjangoValidationError as django_error: raise serializers.ValidationError(django_error.message) application.save() for committee in committees: CommitteePriority.objects.create(committee_application=application, **committee) return CommitteeApplication.objects.get(pk=application.pk)
def test_anon_can_not_apply(self): application = CommitteeApplication() application.application_text = 'something' with self.assertRaises(ValidationError): application.clean()