On 13/04/06, Kevin Dangoor <[EMAIL PROTECTED]> wrote:
>
> On 4/13/06, Ed Singleton <[EMAIL PROTECTED]> wrote:
> >
> > On 13/04/06, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> > > On Thu, Apr 13, 2006 at 10:32:23AM +0100, Ed Singleton wrote:
> > > > Is there a way I can easily add additional properties to a column in
> > > > my table definition?
> > > >
> > > > For example:
> > > >
> > > > class Contact(SQLObject):
> > > > firstName = StringCol(length=64, prettyprint="First Name")
> > > > secondName = StringCol(length=64, prettyprint="Second Name")
> > >
> > > Tere is no. One of the reasons is that columns are not the actual
> > > objects - they are only markers for the metaclass that replaces them with
> > > actual column objects, instances of classess SOStringCol, SOIntCol, etc.
> >
> > Is there a particular way that other people get round this? I'm sure
> > it must be a fairly common thing to want to do.
>
> There are a couple things you can do:
>
> 1) create your own column subclasses with a prettyprint option, if
> this is a common thing for you.
>
> 2) the easy route:
>
> firstName = StringCol(length=64)
> firstName.prettyprint="First Name"
>
> secondName = StringCol(length=64)
> secondName.prettyprint="Second Name"
>
>
> What Oleg is saying makes sense, but I could swear I've seen option #2 in use.
I tried option 1, but am not sure I'm doing it correctly as I get an
attribute error:
File "c:\python24\lib\site-packages\SQLObject-0.7.1dev_r1675-py2.4.egg\sqlobje
ct\col.py", line 413, in __setattr__
self._extra_vars[var] = value
AttributeError: 'Email' object has no attribute '_extra_vars'
When I do:
class Email(StringCol):
def __init__(self):
self.prettyPrint = "Email"
StringCol.__init__(self, length=255, default=None)
class Person(SQLObject):
firstname = StringCol(length=255)
secondname = StringCol(length=255)
email = Email()
For option 2:
email.prettyprint = "Email" doesn't work (Attribute error, 'str'
object has not attribute...)but
emailprettyprint = "Email" does work, so I guess I could use getattr
to access each property by adding the prettyprint to the column name.
Ed
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss