On 06/17/2016 04:45 PM, fer mario wrote:
Hello Guys,

I was having issues cause some empty arguments were treated as ""
(emtpy) instead of none, so the filter() was translating the query as
'where column=""' instead of "where column is NULL", so I'm trying to
write some validation in my add method in my classes:

class Someclass(Object):

   add(self, **kwargs)
      tbl = self.__tablename__
      for key in table.c.keys():
         if key not in kwargs:
            kwargs.setdefault(key, None)

         value = kwargs.get(key)
         if not value:
            kwargs[key] = None

mapper(Someclass, any_table)

Is that possible? if so, can a parent class be written in that way so
child classes will include this validation of the argument based on the
table columns as part of the add method?
Sorry for the questions but I'm new on both worlds (Python and SQLAlchemy)

why not use the normal Python constructor, e.g. __init__()? Otherwise, you can use the init() event (Which can also occur on subclasses): http://docs.sqlalchemy.org/en/rel_1_0/orm/events.html?highlight=init#sqlalchemy.orm.events.InstanceEvents.init





Thanks and kind regards

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to