Re: [SQLObject] Best way to order columns
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Ian B. <ia...@co...> - 2003-07-10 19:56:56
|
On Thu, 2003-07-10 at 14:37, Mark Melvin wrote:
> Yes, of course. Perhaps I am using things in a bad way. In order to
> generate column labels for a list control I am iterating through the
> SQLObject._columns attribute, pulling out .kw['name'] for each one. It is
> a list in a particular order, which I assume is used to generate the
> select() statement because the order appears to match. It does not appear
> to match the order in which the columns are created in my particular class.
> I guess I should look at the source to see how this _columns list is
> created and go from there.
It is probably sorted by the order of the hashes of the strings used to
name the objects, i.e., effectively unsorted. When you do:
class Something(SQLObject):
fname = Col()
lname = Col()
SQLObject (MetaSQLObject to be particular) looks through the classes
*dictionary*, which is of course unordered. If you want to order them
more naturally, you'll have to add another attribute that contains that
ordering (like order=['fname', 'lname']), or do it alphabetically or
something.
I suppose a slightly hackish solution would be to make Col objects
remember what order they were instantiated in. I'm not sure if that's
evil or convenient.
> Cool. I have re-architected my LEFT JOINed approach to be a single table
> and I am finding SQLObject pretty sweet. Simplifying my first case helped
> me a lot to get started, and it should be easier to extend to more
> complicated cases. I found the documentation - while good, is missing a
> lot of the little things. I found myself doing a dir() on object a lot to
> figure out what was in there.
A lot of stuff that is not documented is an unstable interface. You're
welcome to use it of course (I'm a firm opponent of double-underscore
private variables), but be warned it may change. If there's something
in particular that you think is important, bring it up and perhaps we
can make a stable interface for it.
It sounds like you are doing some introspection, which is something in
particular that I have put off until I have a better feel for how it
should work.
Ian
|