Where is the best place to associate a 'form display text' with SQLAlchemy mapped property?
In django orm I can use the 'verbose_name' kwarg to set a label that will be displayed in model forms. Now I'm dynamically generating WTForms for each model in a SQLAlchemy mapped backend, but I'm not sure where to associate a display text to use in the auto generated fields for each form. For example, in django I could do this:
class User(models.Model):
name = CharField(max_length=50, verbose_name='Enter your username')
password = CharField(max_length=50, verbose_name='Enter your password')
In SQLAlchemy:
class User(Base):
name = Column(String)
password = Column(String)
In this simple case, how could I associate the texts 'Enter your username' and 'Enter your passw开发者_Go百科ord' with the 'name' and 'password' attributes respectively?
You could duplicate that functionality by using the 'info' keyword argument to Column. That would look like this:
Class User(Base):
name = Column(String, info={verbose_name: 'Enter your username',})
password = Column(String, info={verbose_name: 'Enter your password',})
Then you could pull info['verbose_name'] out when you dynamically generate a form.
精彩评论