def create(self, validated_data):
    with transaction.atomic():
        facilities = validated_data.pop('facilities', [])
        user = User.objects.create_user(**{**validated_data, 'verified': True})
        user.set_password(validated_data['password'])
        facility_query = self.facility_query(self.context['created_by'])
        if facilities:
            facility_objs = facility_query.filter(external_id__in=facilities)
            facility_user_objs = [FacilityUser(facility=facility, user=user, created_by=self.context['created_by']) for facility in facility_objs]
            FacilityUser.objects.bulk_create(facility_user_objs)
        return user
def create(self, validated_data):
    with transaction.atomic():
        facilities = validated_data.pop('facilities', [])
        user = User.objects.create_user(**{**validated_data, 'verified': True})
        user.set_password(validated_data['password'])
        facility_query = self.facility_query(self.context['created_by'])
        if facilities:
            facility_objs = facility_query.filter(external_id__in=facilities)
            facility_user_objs = [FacilityUser(facility=facility, user=user, created_by=self.context['created_by']) for facility in facility_objs]
            FacilityUser.objects.bulk_create(facility_user_objs)
        return user