Home > python, wxPython > wxPython: Rubrica (un anno dopo) – Model

wxPython: Rubrica (un anno dopo) – Model

Terminate le view, sono passato al modulo Data, nel quale ho creato una classe Model, dove dichiarare tutte le variabili che mi serviranno come appoggio per la gestione dei dati (Controller).
Poi per poter utilizzare l’ORM di SQLAlchemy ho creato la classe Contact, definendo di fatto la tabella e i campi che utilizzerò per il database (sqlite3 nel mio caso).

il codice:

#!/usr/bin/python
#Data.py
'''Data module for sql alchemy ORM'''

from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

class Model(object):
    '''Model class with common application data'''
    base = declarative_base()
    engine = create_engine('sqlite:///contacts.db', echo = True)
    metadata = base.metadata
    def __init__(self):
        self.name = None
        self.surname = None
        self.address = None
        self.mail = None
        self.mobile = None
        self.phone = None
    def get_name(self):
        '''get the contact name'''
        return self.name
    def get_surname(self):
        '''get the contact surname'''
        return self.surname
    def get_address(self):
        '''get the contact address'''
        return self.address
    def get_mail(self):
        '''get the contact mail'''
        return self.mail
    def get_phone(self):
        '''get the contact phone number'''
        return self.phone
    def get_mobile(self):
        '''get the contact mobile number'''
        return self.mobile
    def set_name(self, value):
        '''Sets the contact name to the given value'''
        self.name = value
    def set_surname(self, value):
        '''Sets contact surname to the given value'''
        self.surname = value
    def set_address(self, value):
        '''Sets contact address to the given value'''
        self.address = value
    def set_mail(self, value):
        '''Sets contact mail to the given value'''
        self.mail = value
    def set_phone(self, value):
        '''Sets contact phone to the given value'''
        self.phone = value
    def set_mobile(self, value):
        '''Sets contact mobile to the given value'''
        self.mobile = value

class Contact(Model.base):
    '''Contact class for ORM Mapping'''
    __tablename__ = 'contacts'
    id = Column(Integer, primary_key = True)
    name = Column(String)
    surname = Column(String)
    address = Column(String)
    mail = Column(String)
    mobile = Column(String)
    phone = Column(String)
    
    def __init__(self, name, surname, address, mail, mobile, phone):
        self.name = name
        self.surname = surname
        self.address = address
        self.mail = mail
        self.mobile = mobile
        self.phone = phone
    def __repr__(self):
        return "<Contact ('%s %s')>" % (self.surname, self.name)

continua… (Controller)

Categorie:python, wxPython Tag:,
  1. gennaio 31, 2014 alle 8:47 pm

    I’m truly enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes
    it much more pleasant for me to come here and visit more often.
    Did you hire out a developer to create your theme?
    Superb work!

  2. aprile 16, 2014 alle 4:51 am

    Hi, I would like to subscribe for this web site to get most up-to-date updates,
    so where can i do it please help.

  3. maggio 8, 2014 alle 1:33 am

    Very energetic article, I liked that bit. Will there be a part
    2?

  4. settembre 20, 2014 alle 3:18 am

    Excellent post. I waas checking continuousy thiks
    blog and I am impressed! Veery usefl information specifically thhe last art🙂 I
    care ffor such imfo a lot. I wass looking for this certain infomation for a very llng
    time. Thank youu and bedst oof luck.

  1. maggio 22, 2011 alle 3:25 pm
  2. marzo 26, 2012 alle 1:20 pm
  3. novembre 11, 2014 alle 5:05 pm

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger cliccano Mi Piace per questo: