On Feb 28, 2011, at 8:49 AM, Nickle wrote:

> I have the following code. Simple Calendar and list of holidays. If I
> try and use a Date and datetime.date  I get an error as follows
> 
> Traceback (most recent call last):
>  File "H:\workspace\Test\src\stest.py", line 78, in <module>
>    lon.holidays = [Holiday(lon,
> holiday=datetime.date('2011-01-01'),description='New Year'),
> Holiday(lon, holiday=datetime.date('2011-12-25'),description="xmas")]
> TypeError: an integer is required

that's Python datetime.   the usage is:

datetime.date(2011, 12, 25)




> 
> If I change it to use a string/String for the date, its fine.
> 
> I know there is an issue with Date and Sqlite but I can't fix it.
> 
> The String version is commented out in the holiday_tables code, and it
> works
> 
> Any help appreciated
> 
> =============================
> from sqlalchemy import create_engine
> from sqlalchemy import Table, Column, Date , Integer, String,
> MetaData, ForeignKey
> from sqlalchemy.orm import relationship, backref
> from sqlalchemy.orm import mapper
> from sqlalchemy.orm import sessionmaker
> import datetime
> 
> engine = create_engine('sqlite:///:memory:', echo=True)
> Session = sessionmaker()
> Session.configure(bind=engine)
> session = Session()
> 
> metadata = MetaData()
> 
> class Calendar (object):
> 
>    def __init__(self, name, fullname):
>        self.name = name
>        self.fullname = fullname
> 
>    def __repr__(self):
>        return "<Calendar('%s','%s')>" % (self.name, self.fullname)
> 
> class Holiday (object):
> 
>    def __init__(self, holiday, description):
>        self.holiday     = holiday
>        self.description = description
> 
>    def __repr__(self):
>        return "<Holiday('%s', '%s')>" % (self.holiday,
> self.description)
> 
> calendars_table = Table \
>    (
>    'calendars',
>    metadata,
>    Column('id', Integer, primary_key=True),
>    Column('name', String),
>    Column('fullname', String)
>    )
> 
> holidays_table = Table \
>    (
>    'holidays',
>    metadata,
>    Column('id', Integer, primary_key=True),
>    #Column('holiday', String, nullable=False),
>    Column('holiday', Date, nullable=False),
>    Column('description', String),
>    Column('calendar_id', Integer, ForeignKey('calendars.id'))
>    )
> 
> metadata.create_all(engine)
> 
> mapper \
>    (
>    Calendar,
>    calendars_table,
>    properties= \
>        {
>        'holidays': relationship \
>            (
>            Holiday,
>            backref='calendar',
>            cascade="all, delete, delete-orphan",
>            lazy='joined'
>            )
>        }
>    )
> 
> mapper(Holiday, holidays_table)
> 
> session.commit()
> lon = Calendar('LON', 'London')
> #lon.holidays = [Holiday(holiday='2011-01-01',description='New Year'),
> Holiday(holiday='2011-12-25',description="xmas")]
> session.add(lon)
> session.commit()
> lon.holidays = [Holiday(lon,
> holiday=datetime.date('2011-01-01'),description='New Year'),
> Holiday(lon, holiday=datetime.date('2011-12-25'),description="xmas")]
> session.commit()
> lon = session.query(Calendar).filter_by(name='LON').one()
> session.delete(lon)
> session.commit()
> =====================================
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to