I've been reading the Pylons Book and, having got to the part about Models, realise it's out of date. So I then switched over to the official Pylons documentation for creating Models in Pylons 1.0 - http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/
I've followed what they've got and it's still failing.
./blog/model/init.py
...
I'm writing a small sqlalchemy shim to export data from a MySQL database with some lightweight data transformations—mostly changing field names. My current script works fine but requires me to essentially describe my model twice—once in the class declaration and once as a list of field names to iterate over.
I'm trying to figure out ...
I had my sqlalchemy related code in my main() method in my script.
But then when I created a function, I wasn't able to reference my 'products' mapper because it was in the main() method.
Should I be putting the sqlalchemy related code (session, mapper, and classes) in global scope so all functions in my single file script can refer to...
In this tutorial it says (http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html) to select all rows of an entity like:
s = products.select()
rs = s.execute()
I get an error saying:
This select object is not bound and does not support direct execution ...
Do I need to reference the session object?
I just want to get all rows in my ...
While using SQLAlchemy, i add a object to a session using session.add(objname), then either explicitly flush it using session.flush or enable autoflush=True while creating the engine itself.
Now in the session, if want to return that object via session.query(classname).all(), i cannot retrieve it.
Why is that so? or is there a way in w...
Hello,
I have these classe where items (class Item) is related to channel object:
channel_items = Table(
"channel_items",
metadata,
Column("channel_id", Integer,
ForeignKey("channels.id")),
Column("item_id", Integer,
ForeignKey(Item.id))
)
class Channel(rdb.Model):
""" S...
http://www.sqlalchemy.org/docs/reference/orm/sessions.html
I don't see anything for updating an object that was just retrieved from the database using:
q = session.query(products)
for p in q:
p.blah = 'hello'
sesion.????
session.commit()
...
Select all works like this:
q = session.query(products)
Now I want to add a WHERE filter, so I am trying:
q = session.query(products).filter_by(stock_count=0)
I get an error saying 'nonetype' object has no attribute 'class_manager'.
Not sure what the issue is?
Update
The column seems to be mapped fine, as when I do:
q = session....
Hi,
Is it possible to have the postgres database dump(pg_dump) using SQLAlchemy? i can get the dump using pg_dump but I am doing all other db operations using SQLALchemy and thus want to know if this dump operation is also opssible using SQLAlchemy. Any suggestion, link would be of great help.
Thanks,
Tara Singh
...
So first I am fetching the rows:
q = session.query(products)
for p in q:
p.someproperty = 23
session.commit()
Should the above work in theory? Or is that the wrong pattern?
I am getting an error saying can't modify the property, which is strange so I figured I was doing something fundamentally wrong.
...
Aight ya'll, I gotta lay a Python question on you...
I've been doing some work with Pylons recently and quite like the SQLAlchemy model for database interaction. There's one section of my website though which I think could benefit from an EAV schema.
Using this as my table example:
id | userid | type | value
---+--------+--------|--...
I've read "Multiple database connections with Python + Pylons + SQLAlchemy" and I get how to create multiple engines using that technique, but now I'm looking for advice on how to handle the creation of Sessions for these engines. Right now, the Session in my project is defined as per Pylons convention: myapp.model.meta.Session = scoped_...
I have a table which is being mapped with SqlAlchemy. In that table is a UUID column. When I try to query that table, I get the uuid in bytes_le format. Is there some way I can tell the mapper to return a clean string representation instead? Code for the mapper is:
Practice = Table('Practice',metadata,
schema='pulse...
Hello,
I got this error when I've tried to relate some classes:
"UnmappedClassError: Class 'zeppelinlib.user.UserTest.User' is not mapped"
I don't get errors when I have relation many-to-many.
This is my file where I store all the User classes.
user_channels = Table(
"user_channels",
metadata,
Col...
I've been working on a Pylons site and just now started to create my database. I made my User model class and then issued paster setup-app development.ini. Worked great.
However, now when I try to paster serve --reload development.ini, I get the following error:
ConfigParser.MissingSectionHeaderError: File contains no section headers.
...
Hi,
I'm getting myself into issues with python class attributes vs data attributes in my sqlalchemy model. This is a small example to demonstrate what's happening:
# -*- coding: utf-8 -*-
import cherrypy
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
fr...
Hello,
I have these classes:
class Channel(rdb.Model):
rdb.metadata(metadata)
rdb.tablename("channels")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
items = relationship("MediaItem", secondary=channel_items, order_by="MediaItem.titleView", backref="channels")
class MediaItem(...
I want to override __cmp__, __eq__, and __hash__ so I can do set operations on a SQLAlchemy Declarative Base model. Will this cause any conflicts with the Declarative Base Implementation?
...
What is the best way to create a one-to-one relationship in SQLAlchemy using declarative?
I have two tables, foo and bar, and I want foo.bar_id to link to bar. The catch is that this is a one-way one-to-one relationship. bar must not know anything about foo. For every foo, there will be one and only one bar.
Ideally, after selecting a...
Hello,
I'm trying to link one table to itself. I have media groups which can contain more media group. I created a relation many to many:
media_group_groups = Table(
"media_group_groups",
metadata,
Column("groupA_id", Integer, ForeignKey("media_groups.id")),
Column("groupB_id", Integer, F...