擅长:python、mysql、java
<p>您应该考虑使用父类,从中可以继承,这在python中很容易做到:</p>
<pre><code>class Parent_class(object):
def get_status_choices(self):
return ((0, gettext("disabled")), (1, gettext("allowed")))
class UserDevice(BaseModel, Parent_class):
# your implementation...
status = IntegerField(choices=self.get_status_choices(), default=1)
# and further implementations....
class UserDeviceAdmin(ModelView, Parent_class):
# your implementation...
column_choices = {'status': self.get_status_choices()}
# and further implementations....
</code></pre>
<p>注意,最好将父类的名称更改为域中相关的名称</p>