|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Simple questionHi I'm new at TurboGears and am getting slightly confused/lost by the SQLObject docs. I would be grateful if somebody could explain what the easiest way to get the ems_name of a record in Ne_live is. b=Ne_live.get(4) b.Ems_live.ems_name ????????? Traceback (most recent call last): File "<console>", line 1, in ? AttributeError: 'Ne_live' object has no attribute 'Ems_live' c.ne_ems_id.ems_name ????? Traceback (most recent call last): File "<console>", line 1, in ? AttributeError: 'int' object has no attribute 'ems_name' class Ems_live(SQLObject): class sqlmeta: idName = "ems_id" ems_name = StringCol() ems_sm_time = DateTimeCol() ems_sm_code = IntCol() class Ne_live(SQLObject): class sqlmeta: idName = "ne_id" ne_ems_id = ForeignKey("Ems_live") ne_name = StringCol() Many thanks Jon --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionOn Wed, Jul 2, 2008 at 12:21 PM, jrpfinch <jrpfinch@...> wrote:
First, if you're just getting started with TG, you might really want to consider using SQLAlchemy rather than SQLObject. I totally understand if you want to take the learning curve in small doses, though. Second, I think (based on a hazy memory of SQLObject), that you want something like: b=Ne_live.get(4) b.ne_ems_id.ems_name You might want to check out this tutorial for more info: http://exogen.case.edu/turbogears.html It's a little outdated, but it should give you an idea. Good luck! Kevin Horn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionThanks Kevin, I will look into SQLAlchemy. Unfortunately, b.ne_ems_id.ems_name does not work I just get the following: Traceback (most recent call last): File "<console>", line 1, in ? AttributeError: 'int' object has no attribute 'ems_name' If it matters, I am using pymssql On 2 Jul, 19:27, "Kevin Horn" <kevin.h...@...> wrote: > On Wed, Jul 2, 2008 at 12:21 PM, jrpfinch <jrpfi...@...> wrote: > > > Hi I'm new at TurboGears and am getting slightly confused/lost by the > > SQLObject docs. > > > I would be grateful if somebody could explain what the easiest way to > > get the ems_name of a record in Ne_live is. > > > b=Ne_live.get(4) > > b.Ems_live.ems_name ????????? > > Traceback (most recent call last): > > File "<console>", line 1, in ? > > AttributeError: 'Ne_live' object has no attribute 'Ems_live' > > c.ne_ems_id.ems_name ????? > > Traceback (most recent call last): > > File "<console>", line 1, in ? > > AttributeError: 'int' object has no attribute 'ems_name' > > > class Ems_live(SQLObject): > > class sqlmeta: > > idName = "ems_id" > > ems_name = StringCol() > > ems_sm_time = DateTimeCol() > > ems_sm_code = IntCol() > > > class Ne_live(SQLObject): > > class sqlmeta: > > idName = "ne_id" > > ne_ems_id = ForeignKey("Ems_live") > > ne_name = StringCol() > > > Many thanks > > > Jon > > First, if you're just getting started with TG, you might really want to > consider using SQLAlchemy rather than SQLObject. I totally understand if > you want to take the learning curve in small doses, though. > > Second, I think (based on a hazy memory of SQLObject), that you want > something like: > > b=Ne_live.get(4) > b.ne_ems_id.ems_name > > You might want to check out this tutorial for more info:http://exogen.case.edu/turbogears.html > > It's a little outdated, but it should give you an idea. > > Good luck! > > Kevin Horn You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionOn Wed, Jul 2, 2008 at 1:39 PM, jrpfinch <jrpfinch@...> wrote:
Hmmm, you might also try changing: ne_ems_id = ForeignKey("Ems_live") to: ne_ems = ForeignKey("Ems_live") or something similar...I remember that SQLObject has some kind of implicit id column naming stuff that caused me issues in the past. You may have problems if the column name in your SQLObject is the same as the auto-generated column name in your DB table, but I really can't recall whether that would affect you in this particular case. Kevin Horn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionOn 2 Jul, 19:45, "Kevin Horn" <kevin.h...@...> wrote: > On Wed, Jul 2, 2008 at 1:39 PM, jrpfinch <jrpfi...@...> wrote: > > > Thanks Kevin, I will look into SQLAlchemy. > > > Unfortunately, b.ne_ems_id.ems_name does not work I just get the > > following: > > > Traceback (most recent call last): > > File "<console>", line 1, in ? > > AttributeError: 'int' object has no attribute 'ems_name' > > > If it matters, I am using pymssql > > > On 2 Jul, 19:27, "Kevin Horn" <kevin.h...@...> wrote: > > > On Wed, Jul 2, 2008 at 12:21 PM, jrpfinch <jrpfi...@...> wrote: > > > > > Hi I'm new at TurboGears and am getting slightly confused/lost by the > > > > SQLObject docs. > > > > > I would be grateful if somebody could explain what the easiest way to > > > > get the ems_name of a record in Ne_live is. > > > > > b=Ne_live.get(4) > > > > b.Ems_live.ems_name ????????? > > > > Traceback (most recent call last): > > > > File "<console>", line 1, in ? > > > > AttributeError: 'Ne_live' object has no attribute 'Ems_live' > > > > c.ne_ems_id.ems_name ????? > > > > Traceback (most recent call last): > > > > File "<console>", line 1, in ? > > > > AttributeError: 'int' object has no attribute 'ems_name' > > > > > class Ems_live(SQLObject): > > > > class sqlmeta: > > > > idName = "ems_id" > > > > ems_name = StringCol() > > > > ems_sm_time = DateTimeCol() > > > > ems_sm_code = IntCol() > > > > > class Ne_live(SQLObject): > > > > class sqlmeta: > > > > idName = "ne_id" > > > > ne_ems_id = ForeignKey("Ems_live") > > > > ne_name = StringCol() > > > > > Many thanks > > > > > Jon > > > > First, if you're just getting started with TG, you might really want to > > > consider using SQLAlchemy rather than SQLObject. I totally understand if > > > you want to take the learning curve in small doses, though. > > > > Second, I think (based on a hazy memory of SQLObject), that you want > > > something like: > > > > b=Ne_live.get(4) > > > b.ne_ems_id.ems_name > > > > You might want to check out this tutorial for more info: > >http://exogen.case.edu/turbogears.html > > > > It's a little outdated, but it should give you an idea. > > > > Good luck! > > > > Kevin Horn > > Hmmm, you might also try changing: > > ne_ems_id = ForeignKey("Ems_live") > > to: > > ne_ems = ForeignKey("Ems_live") > > or something similar...I remember that SQLObject has some kind of implicit > id column naming stuff that caused me issues in the past. > You may have problems if the column name in your SQLObject is the same as > the auto-generated column name in your DB table, but > I really can't recall whether that would affect you in this particular case. > > Kevin Horn Unfortunately I can't change ne_ems_id to ne_ems because I have not control over the structure of the underlying database --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionjrpfinch schrieb: >> Hmmm, you might also try changing: >> >> ne_ems_id = ForeignKey("Ems_live") >> >> to: >> >> ne_ems = ForeignKey("Ems_live") >> > > Unfortunately I can't change ne_ems_id to ne_ems because I have not > control over the structure of the underlying database No, that doesn't mean that the column name in the underlying database will be 'ne_ems'. SQLObject will build the right column name with some name-mangling magic automatically. Just try it out. For details please read the SQLAlchemy docs. There are also ways to influence how this name-mangling actually works, but again, you have to check the SO docs for that. Then again, if you need full control over the column names in the database, SQLAlchemy will probably work better for you. Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionOn Wed, Jul 2, 2008 at 1:54 PM, jrpfinch <jrpfinch@...> wrote:
What I'm saying is that the reference in your SQLObject should be named something _other_ than what the id column is named in your database. SQLObject then creates what it thinks should be the name of the column in the database to use internally. So the So if you have something like:(taken from the tutorial I referenced earlier): then you should be able to access it by:class User(SQLObject): listObject = List.get(some_id) listObject.user.email but in the actual database, the column name will be something like"user_id" or "userID". If you are dealing with a legacy database then I _really_ suggest that you go with SQLAlchemy. It gives you much better control over this sort of thing. SQLObject tries to do too much "automagically" in this area. Kevin Horn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple questionOn 2 Jul, 20:00, Christopher Arndt <chris.ar...@...> wrote: > jrpfinch schrieb: > > >> Hmmm, you might also try changing: > > >> ne_ems_id = ForeignKey("Ems_live") > > >> to: > > >> ne_ems = ForeignKey("Ems_live") > > > Unfortunately I can't change ne_ems_id to ne_ems because I have not > > control over the structure of the underlying database > > No, that doesn't mean that the column name in the underlying database > will be 'ne_ems'. SQLObject will build the right column name with some > name-mangling magic automatically. Just try it out. > > For details please read the SQLAlchemy docs. There are also ways to > influence how this name-mangling actually works, but again, you have to > check the SO docs for that. > > Then again, if you need full control over the column names in the > database, SQLAlchemy will probably work better for you. > > Chris dir(b) in the tg-admin shell, a bit of trial and error and i've discovered that the following works: b.ne_ems_.ems_name I'll take a look in the SO docs but if anyone knows how I could influence this name-mangling without editing the underlying database, I would be very grateful thank you Kevin and Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple question> > Unfortunately I can't change ne_ems_id to ne_ems because I have not > control over the structure of the underlying database ForeignKey will append the _id for a foreign key by itself. So you *can* change it. And even if your convention wouldn't be so conforming, you can change it using a parameter to ForeignKey. I'm not 100% sure which that is though - try "foreignKey" or "name". While I like SO, you might really be better of using SA when you have to cope with a given schema - it is better suited for that. Diez --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears-unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free Forum Powered by Nabble | Forum Help |