old boy Education Python Automation 2.0 Course Courseware Catalogue http://www.cnblogs.com/alex3714/articles/5885096.htmlDay1-python Basics 1 Introduction, basic syntax, Process Control
Day2-python base 2 list, dictionary, collection
Day3-python Basic 3 functions, recursion, built-in functions
Day4-python Basic 4 iterator, adorner, software development specification
Day5-python Basic 5 Common Module learning
Day6-python basic 6 Object-oriented programming
Day7-python Basic 7 Object-oriented programming advanced
Day8-python Network Programming Socket programming
Day9-python multi-threading, process
Day10-python, asynchronous Io, Redis cache, RABBITMQ queue
Day11-mysql and ORM
DAY12-Fortress Machine development
Html+css+js
Day16-it ' s time for Django
Day17-django appropriate advanced article
Day18-django Advanced
Day---Twisted---redis---rabbitmq
windows under Redis installation https://www.cnblogs.com/jaign/articles/7920588.html
Windows RABBITMQ installation http://blog.csdn.net/hzw19920329/article/details/53156015from SQLAlchemy import Create_engine
Http://www.cnblogs.com/alex3714/articles/5248247.html
Day 11th SQLAlchemy
One-to-many
1 fromSqlalchemy.ext.declarativeImportDeclarative_base2 fromSQLAlchemyImportColumn, Integer, String, foreignkey,func,table3 fromSqlalchemy.ormImportSessionmaker, Relationship4Base = Declarative_base ()#generates a Sqlorm base class5Mima ='! saiyun12#$'6Host2group = Table ('Host_2_group', Base.metadata,7Column ('host_id', ForeignKey ('hosts.id'), primary_key=True),8Column ('goup_id', ForeignKey ('group.id'), primary_key=True),9 )TenEngine = Create_engine ("Mysql+pymysql://root:%[email Protected]/testdb"% mima,encoding='Utf-8', echo=True) One classHost (Base): A __tablename__='hosts' -id = Column (integer,primary_key=true,autoincrement=True) -hostname = Column (String), unique=true,nullable=False) theIP_ADDR = Column (String), unique=true,nullable=False) -Port = Column (integer,default=22) -group_id = Column (Integer,foreignkey ('group.id')) -Group = relationship ("Group", backref='host_list') + classGroup (Base): - __tablename__='Group' +id = Column (integer,primary_key=True) AName = Column (String), unique=true,nullable=False) atBase.metadata.create_all (Engine)#Create all table Structures - if __name__=='__main__': -Sessioncls = Sessionmaker (bind=engine)#create a session with the database sessions class, note that this is a class that is returned to the session, not an instance -Session =sessioncls () -OBJS = Session.query (Host,func.count (Group.name)). Join (Host.group). group_by (Group.name). All ()#JOIN Operation - Print("---->", OBJS) inSession.commit ()#Submit - " "the OST SQL corresponding to obj to SELECT hosts.id as hosts_id, hosts.hostname as Hosts_hostname, hosts.ip_addr as Hosts_ip_addr, Hosts.port as Hosts_por T, + hosts.group_id as hosts_group_id, Count (' group '. Name) as Count_1 - From the hosts INNER JOIN ' group ' on ' group '. ID = hosts.group_id GROUP by ' group '. Name the # # # #select * from the hosts right join Testdb.group on hosts.group_id = Testdb.group.id * " "
View Code
Many-to-many
1 fromSQLAlchemyImportCreate_engine2 fromSqlalchemy.ext.declarativeImportDeclarative_base3 fromSQLAlchemyImportColumn, Integer, String, foreignkey,func,table4 fromSqlalchemy.ormImportSessionmaker, Relationship5Base = Declarative_base ()#generates a Sqlorm base class6Mima ='! saiyun12#$'7Host2group = Table ('Host_2_group', Base.metadata,8Column ('host_id', ForeignKey ('hosts.id'), primary_key=True),9Column ('goup_id', ForeignKey ('group.id'), primary_key=True),Ten ) OneEngine = Create_engine ("Mysql+pymysql://root:%[email Protected]/testdb"% mima,encoding='Utf-8', echo=True) A classHost (Base): - __tablename__='hosts' -id = Column (integer,primary_key=true,autoincrement=True) thehostname = Column (String), unique=true,nullable=False) -IP_ADDR = Column (String), unique=true,nullable=False) -Port = Column (integer,default=22) -Groups = Relationship ('Group', secondary=host2group,backref='host_list') + #group_id = Column (Integer,foreignkey (' group.id ')) - #Group = relationship ("group", backref= ' host_list ') + classGroup (Base): A __tablename__='Group' atid = Column (integer,primary_key=True) -Name = Column (String), unique=true,nullable=False) -Base.metadata.create_all (Engine)#Create all table Structures - if __name__=='__main__': -Sessioncls = Sessionmaker (bind=engine)#create a session with the database sessions class, note that this is a class that is returned to the session, not an instance -Session =sessioncls () in #g1= Group (name= ' G1 ') - #g2 = Group (name= ' G2 ') to #g3 = Group (name= ' G3 ') + #G4 = Group (name= ' G4 ') - #Session.add_all ([g1,g2,g3,g4]) the #H1 = Host (hostname= ' H1 ', ip_addr= ' 192.168.1.56 ', port=1000) * #h2 = Host (hostname= ' H2 ', ip_addr= ' 192.168.1.57 ', port=1002) $ #h3 = Host (hostname= ' H3 ', ip_addr= ' 192.168.1.58 ', port=1003)Panax Notoginseng #Session.add_all ([h1,h2,h3]) -groups=session.query (Group). All () theH1 = Session.query (Host). Filter (host.hostname=='H1'). First () +H1.groups = Groups#create a many-to-many relationship for the existing host and group tables A the #Objs = Session.query (Host,func.count (Group.name)). Join (Host.group). group_by (Group.name). All () #join操作 + #print ("---->", OBJS) -Session.commit ()#Submit
View Code
Nihao Hello World
Xiaofeng
The path to learning Python