-
Notifications
You must be signed in to change notification settings - Fork 0
Add pinyin mnemonic support to a model
Lawrence Liu edited this page May 7, 2017
·
2 revisions
如果希望在单据或者数据列表页面,可以用拼音首字母来搜索供应商、产品、客户等,可以使用下面的方法,增加这个功能。
- Add field mnemonic to the model with type string as below
mnemonic = Column(String(64), unique=False, nullable=True)
- Generate DB migrate using follow command in the project root folder
python manage.py db migrate
- Add event listener in psi/app/models/aspect.py as below
# Customer is the model name
@event.listens_for(Customer, 'before_insert')
@event.listens_for(Customer, 'before_update')
- If you just like to use "name" field as the mnemonic source, then that's done, if you would like to use a custom mnemonic, then you can implement method get_value_for_mnemonic in the model definition, for example
# Use field last_name and first_name as source of the mnemonic.
def get_value_for_mnemonic(self):
return get_name(self.last_name, self.first_name)
- Samples in the code
# models/Customer.py
# models/Supplier.py
# models/Product.py