[orm-devel] Access to attributes before a query

Mike Watkins mw@mikewatkins.net
Sat, 16 Nov 2002 16:30:15 -0800 (PST)


Diedrich Vorberg said:
>Wait... do this:
>
> def mikes_dbclass(dbclass):
>     defaults = {} # Mike's dbclasses need a defaults dict whoes keys
>                   # must be a subset to columns' keys and which
>                   # contains a default value for each column that  #
> needs one
>
>     def __init__(self, **kwargs):
>         data = {}
>         for column in self.columns.keys():
>             if kwargs.has_key(column):           # if a value is passwd
>                 data[column] = kwargs[column]    # as argument use it
>             elif self.defaults.has_key(column):  # if not
>                 data[column] = defaults[column]  # use a default
>
>         dbclass.__init__(self, **data)           # does the job!
>
> class item(mikes_dbclass):
>     columns = ....
>
> Actually this might be a good thing to put into orm .... :-)
>
> What'd y' think?

Yes, this looks good. I'll play while you sleep!


>>I agree - still thinking that attributes set to None would be ignored -
>> maybe we need an ORM "null" type
> I really like this idea! I will give it some thought. Too late
> now, it just turned midnight...
>

Still daylight here on the west coast of Canada... ;)