flask peewee如何在编辑/创建表单时更改字段顺序

时间:2017-05-05 02:41:55

标签: flask peewee flask-admin

对于模型User,我想在其中放置一个内联模型ProjectNotes,以及如何  我可以在创建或编辑时更改字段顺序吗?  例如,将订单更改为ProjectNotes, username, email.(参见下面的图片。)

class User(BaseModel):
   username = peewee.CharField(max_length=80)
   email = peewee.CharField(max_length=120)

   def __unicode__(self):
       return self.username

class ProjectNotes(BaseModel):
   comment = peewee.CharField(max_length=64)
   user = peewee.ForeignKeyField(User)

   def __unicode__(self):
       return '%s - %s' % (self.comment)

class UserAdmin(ModelView):
   inline_models = (ProjectNotes,)

admin.add_view(UserAdmin(User))

enter image description here

1 个答案:

答案 0 :(得分:1)

form_columns可以form_labelcolumn_labelsinline_models class UserAdmin(ModelView): inline_models = [ (ProjectNotes, {'form_columns': ('user', 'comment')}) ] 作为字典:

ProjectNotes

或为from flask_admin.model.form import InlineFormAdmin class ProjectNotesAdmin(InlineFormAdmin): form_columns = ('user', 'comment') class UserAdmin(ModelView): inline_models = [ProjectNotesAdmin(ProjectNotes)] 模型创建表单类:

form_columns

我还发现我需要在flask_admin.contrib.sqla.ModelView中为flask_admin.contrib.peewee.ModelView指定主键列。不知道你是否需要对 mySwitch.setChecked(false); mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { final Handler handler = new Handler(); final Runnable r = new Runnable() { public void run() { myClient.SendData("AA"); handler.postDelayed(this, 1000); } }; if (isChecked){ handler.postDelayed(r, 1000); } else { handler.removeCallbacks(r); } } }); 做同样的事情。