Creating a new model

We'll start in models.py by importing psycopg2 and DictCursor:

import psycopg2 as pg
from psycopg2.extras import DictCursor

DictCursor will allow us to fetch results in Python dictionary rather than the default tuples, which is easier to work with in our application.

Begin a new model class called SQLModel and copy over the fields property from the CSVModel.

Start by clearing the value lists from Technician, Lab, and Plot, and making Technician an FT.string_list type:

class SQLModel:
    fields = {
        ...
        "Technician": {'req': True, 'type': FT.string_list,                        'values': []},
        "Lab": {'req': True, 'type': FT.string_list, 'values': []},
        "Plot": {'req': True, 'type': FT.string_list,'values': []},
     

These lists will be populated from ...

Get Python GUI Programming - A Complete Reference Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.