[Flask] Macro expansion/evaluation?
Jim Icenhower
jicenhower at yahoo.com
Wed Oct 14 19:19:46 CEST 2015
Hi All,I'm sure this is a newbie question but I haven't been able to find the answer by searching. Probably because I don't know what this technique is called in Python. I have created a class which extends the Flask-Appbuilder Model class which extends a SQLAlchemy class. I'm trying to validate that all required fields are populated. I have created this function that returns all the mapped attributes of the class:
def get_obj_mapped_columns(dbObj):
mapper = inspect(dbObj)
return mapper.mapper.columns
This is my main class:
class Event(Model):
EventID = Column(Integer, primary_key=True)
EventKey = Column(String(30), unique=True, nullable=False)
Name = Column(String(100), nullable=False)
Description = Column(Text(1000), nullable=False)
BeginDate = Column(Date)
EndDate = Column(Date)
RegBeginDate = Column(Date)
RegEndDate = Column(Date)
Location = Column(String(200))
Address1 = Column(String(200))
Address2 = Column(String(200))
City = Column(String(20))
State = Column(String(2))
Zip = Column(String(10))
URL = Column(String(100))
Email = Column(String(100))
Phone = Column(String(20))Which contains the following method: def isValid(self):
columns = get_obj_mapped_columns(self)
for column in columns:
if (NOT column.nullable):
print column.name
print self.<column.name>
I would like to substitute the value in <column.name> in such a way that it is evaluated as the field name of the Event object.
Any guidance would be greatly appreciated!
Thanks,Jim Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20151014/0f52a30e/attachment.html>
More information about the Flask
mailing list