Job Search Engine


1702 浏览 5 years, 8 months

1.2.1 sqlalchemy

版权声明: 转载请注明出处 http://www.codingsoho.com/
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-2: ordinal not in range(256)

两种办法:

self.engine=create_engine("mysql://user:pass@localhost/test",connect_args={'charset':'utf8'}) workaround 1, take effect
self.engine=create_engine("mysql://user:pass@localhost/test?charset=utf8") #workaround 2, take effect
AttributeError: 'InstrumentedList' object has no attribute 'filter'
            from sqlalchemy import Date, cast
            from datetime import date
            # job_entries_objs = record.job_entries.filter(cast(JobEntry.created,Date) == date.today()).all() 
            job_entries_objs = record.job_entries.filter(JobEntry.created > oneDayAgo ).all() 
class JobEntry(Base):
    __tablename__='job_entry'    
    id = Column(Integer, nullable=False, primary_key=True, autoincrement=True)
    title = Column(String(200))
    salary = Column(String(45))
    region = Column(String(45))
    degree = Column(String(45))
    experience = Column(String(45))
    company = Column(String(145))
    industry = Column(String(145))
    description = Column(Text(300))
    href = Column(String(100))
    # created = Column(DateTime, default=datetime.datetime.utcnow)
    # updated = Column(DateTime, default=datetime.datetime.utcnow)
    created = Column(DateTime, default=datetime.datetime.now)
    updated = Column(DateTime, default=datetime.datetime.now)        
    trigger_scrap_records = relationship('TriggerScrapRecord',
            secondary = job_entry_m2m_trigger_scrap_record, 
            # backref = 'job_entries', 
            backref=('job_entries', {'lazy':'dynamic'}),
            # cascade="all, delete-orphan", # delete-orphan cascade is not supported on a many-to-many or many-to-one relationship when single_parent is not set.
            lazy='dynamic',
            passive_deletes=True)    
    def __repr__(self):
        return self.title