On 9/6/06, Enrico Morelli <[EMAIL PROTECTED]> wrote: > Thanks again Arnar, > > I'm sorry for my stupidity and for the time that you loose for me. > But I'm going crazy to understand everything. My brain is in overeating > state ;-)) Speaking in sqlAlchemy code:
Not knowing stuff doesn't mean you're stupid :) > > rules.. you should keep a table of days (with cols year, month, day) - > > but since this is an easily recreatable dataset, no table is really > > neccessary here. > > days=Table('days', metadata, > Column('days_id', Integer, primary_key=True), > Column('year', Integer), > Column('month', Integer), > Column('day', Integer)) > > instrument=Table('instruments', metadata, > Column('instrument_id', Integer, primary_key=True), > Column('name', String)) > > > > planning=Table('planning', metadata, > Column('planning_id', Integer, primary_key=True), > Column('instrument_id', Integer,ForeignKey('instruments.instrument_id')), > Column('days_id', Integer, ForeignKey('days.days_id')), > Column('data', String)) > > I've already loose the way.... > > class Days(object): pass > class Instrument(object): pass > class Planning(object): pass > > mapper(Days, days) > mapper(Instruments, instruments) > mapper(Planning, planning, > properties={ 'instruments' :relation(Instruments), > 'days' : relation(Days)}) You could do something like this: instruments=Table('instruments', metadata, Column('instrument_id', Integer, primary_key=True), Column('name', String)) plan=Table('plan', metadata, Column('year', Integer, primary_key=True), Column('month', Integer, primary_key=True), Column('day', Integer, primary_key=True), Column('instrument_id', Integer, primary_key=True, ForeignKey('instruments.instrument_id')), Column('data', String)) class PlanEntry: pass class Instrument: pass mapper(Instrument, instruments) mapper(PlanEntry, plan, properties={ 'instrument': relation(Instrument) }) - Given a year Y and month M, this gives you plan entries for that month: entries = session.query(PlanEntry).select_by(year=Y, month=M) - Building the table: def find_entry_with_instrument(entries, aninstrument): for e in entries: if e.instrument == aninstrument: return e return None # instrument not found in list thetable = [] allinstruments = session.query(Instrument).select() for d in range(1,daysinmonth(M)+1): row = [] entries_for_this_day = [e for e in entries if e.day == d] for i in allinstruments: entry = find_entry_with_instrument(entries_for_this_day, i) if entry is not None: row.append(entry.data) else: row.append('') thetable.append(row) > Please, if you can help me I offer you a wonderful coffee if you come to > Florence. Thanks :) Arnar ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users