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 with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.