librelist archives

« back to archive

dynamically accessing specific entry in database (SQLAlchemy)

dynamically accessing specific entry in database (SQLAlchemy)

From:
Yifan Wu
Date:
2013-02-03 @ 15:57
Hi,

I was wondering if there is a way to *map string to a specific data
entry*of a row in the database so I could dynamically render the
content based on
url input. Right now what I pass in is treated as a string and is thus not
callable; but I cannot create a mapping either because I don't want the
entry to be tied with a specific table --- is it even possible?

Thanks for the help!

-Yifan

Re: [flask] dynamically accessing specific entry in database (SQLAlchemy)

From:
Steven Kryskalla
Date:
2013-02-03 @ 19:55
On Sun, Feb 3, 2013 at 7:57 AM, Yifan Wu <yifan1030@gmail.com> wrote:
> I was wondering if there is a way to map string to a specific data entry of
> a row in the database so I could dynamically render the content based on url
> input. Right now what I pass in is treated as a string and is thus not
> callable; but I cannot create a mapping either because I don't want the
> entry to be tied with a specific table --- is it even possible?

Do you mean looking up an attribute by name from a string? Like this?

>>> class User(object):
...     name = "test"
...
>>> getattr(User, 'name')
'test'
>>>

Re: [flask] dynamically accessing specific entry in database (SQLAlchemy)

From:
Yifan Wu
Date:
2013-02-03 @ 20:33
awesome; thanks so much!

-Yifan


On Sun, Feb 3, 2013 at 2:55 PM, Steven Kryskalla <skryskalla@gmail.com>wrote:

> On Sun, Feb 3, 2013 at 7:57 AM, Yifan Wu <yifan1030@gmail.com> wrote:
> > I was wondering if there is a way to map string to a specific data entry
> of
> > a row in the database so I could dynamically render the content based on
> url
> > input. Right now what I pass in is treated as a string and is thus not
> > callable; but I cannot create a mapping either because I don't want the
> > entry to be tied with a specific table --- is it even possible?
>
> Do you mean looking up an attribute by name from a string? Like this?
>
> >>> class User(object):
> ...     name = "test"
> ...
> >>> getattr(User, 'name')
> 'test'
> >>>
>