On 5/3/07, Thierry <[EMAIL PROTECTED]> wrote:
>
> I have the following in model.py:
>
> class Greet(SQLObject):
> class sqlmeta:
> fromDatabase = True
>
> def _get_greetings(self):
> c = Greet._connection
> return c.queryAll('SELECT distinct greeting FROM Greets')
>
>
> The only way I can retrieve the value of greetings in controllers.py
> is the following:
>
> g = Greet()
> return dict(greets=g.greetings)
>
> All I want to do is get some values from the database, is there an
> alternative way of doing the above?
I think that _get_greetings should be a classmethod:
@classmethod
def all_greetings(cls):
c = Greet._connection
return c.queryAll('SELECT distinct greeting FROM Greets')
Then you don't need an instance to call the method:
Greet.all_greetings()
However, it might be better to just get rid of that method and do:
greetings = [g.greeting for g in Greet.select()]
perhaps?
Regards -- Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---