@staticmethod
    def add_question(template_id, name, code, notes, qtype, posn, metadata={}):

        db = current.db
        s3db = current.s3db

        # Add the question to the database if it's not already there
        qtable = s3db.survey_question
        query = (qtable.name == name) & \
                (qtable.code == code)
        record = db(query).select(qtable.id, limitby=(0, 1)).first()
        if record:
            qstn_id = record.id
        else:
            qstn_id = qtable.insert(name = name,
                                    code = code,
                                    notes = notes,
                                    type = qtype,
                                    )
            qstn_metadata_table = s3db.survey_question_metadata
            for (descriptor, value) in metadata.items():
                qstn_metadata_table.insert(question_id = qstn_id,
                                           descriptor = descriptor,
                                           value = value,
                                           )
        # Add these questions to the section: "Background Information"
        sectable = s3db.survey_section
        section_name = "Background Information"
        query = (sectable.name == section_name) & \
                (sectable.template_id == template_id)
        record = db(query).select(sectable.id, limitby=(0, 1)).first()
        if record:
            section_id = record.id
        else:
            section_id = sectable.insert(name = section_name,
                                         template_id = template_id,
                                         posn = 0 # special section with no position
                                         )
        # Add the question to the list of questions in the template
        qltable = s3db.survey_question_list
        query = (qltable.question_id == qstn_id) & \
                (qltable.template_id == template_id)
        record = db(query).select(qtable.id, limitby=(0, 1)).first()
        if not record:
            qltable.insert(question_id = qstn_id,
                           template_id = template_id,
                           section_id = section_id,
                           posn = posn,
                           )

    # -------------------------------------------------------------------------
Adds a question to the template corresponding to template_id
dataset/ETHPy150Open sahana/eden/modules/s3db/survey.py/S3SurveyTemplateModel.add_question