I've just created a simple quotes model and if I populate the db I can
get records fine. sql create worked all peachy. What I can't get, is how
to save records created. I just created a method in the model:
class UserQuotes(Entity):
has_field('project', Unicode(100), primary_key=True)
has_field('user_name', Unicode(100))
has_field('user_quote', Unicode)
has_field('year', Integer)
@staticmethod
def load_default_data():
quote1 = UserQuotes(project="Test1",
user_name="Rick",
user_quote="This is the other quote",
year="2007")
quote2 = UserQuotes(project="Test2",
user_name="Erica",
user_quote="This is my quote for it",
year="2006")
objectstore.flush()
Ok, looks good, except nothing makes it to the database. My controller
method is just:
@expose()
def load_default(self):
UserQuotes.load_default_data()
return dict()
I don't get any errors, but nadda in the db. So what am I missing? using
objectstore.flush() is the only method of saving the created objects in
the tutorial. In their sample TG app they only fetch rows and there's no
code/method for editing/saving new movie records.
Is there any other sample code out there I can get my hands on?
Thanks for the help.
Rick
So I decided to try to just do this with SA and changed everything
around with the same results. It just won't write to the db. I don't get
it. In my dev.cfg I have sqlalchemy.echo = 1
My SA version of the model/method:
Model
----------------------------------
quotes_table = Table("avwsystems_model_userquotes", metadata,
Column("project", Unicode(100), primary_key=True),
Column("user_name", Unicode(100)),
Column('user_quote', Unicode),
Column("year", Integer)
)
class Quotes(object):
pass
quote_mapper = mapper(Quotes, quotes_table)
Controller
-------------------------------------
@expose()
def load_default(self):
session = database.session
q = Quotes()
q.project = "Test1"
session.save(q)
return 'done'
The only output to the terminal is the GET request. My display is just
Done printed in the browser.
Sorry to make it seem Elixir specific, but it seems to be more general
than that.
Thanks for any help.
Rick
I spend some time and T` on IRC helped me get it all squared away. My
method now looks like this and it works. Much nicer/prettier than it
originally was.
@staticmethod
def load_quote():
q = Quotes()
q.project = 'testing'
q.flush()
So from the best I can tell, the .save() is auto handled
somewhere/somehow and I have just have to do the flush() manually
whenever I want to commit the change.
Rick