class UserForm(UserForm): # Embeds OneToOne as FormField profile = wtforms.FormField( model_form(Profile, db_session, exclude=['user'], base_class=wtforms.Form))
def __new__(cls, *args, **kwargs): if not cls.model: raise Exception('ModelAdminModule must provide `model` attribute') if not cls.list_fields: cls.list_fields = OrderedMultiDict() for column in cls.model.__table__._columns: cls.list_fields[column.name] = {'label': column.name, 'column': getattr(cls.model, column.name)} if not cls.form_class: cls.form_class = model_form(cls.model, cls.db_session) return super(ModelAdminModule, cls).__new__(cls, *args, **kwargs)
def __repr__(self): return '<Group %r>' % self.name db.drop_all() db.create_all() group = Group(name="admin") db_session.add(group) company = Company(name="My company") db_session.add(company) db_session.commit() UserForm = model_form(User, db_session, exclude=['password']) class UserForm(UserForm): # Embeds OneToOne as FormField profile = wtforms.FormField( model_form(Profile, db_session, exclude=['user'], base_class=wtforms.Form)) class UserModule(ModelAdminModule): model = User db_session = db_session profile_alias = aliased(Profile) list_fields = OrderedMultiDict((
class CompanyModule(ModelAdminModule): model = Company db_session = db_session form_class = model_form(Company, db_session, only=['name'])
class GroupModule(ModelAdminModule): model = Group db_session = db_session form_class = model_form(Group, db_session, only=['name'])
return str(self.name) def __repr__(self): return '<Group %r>' % self.name db.drop_all() db.create_all() group = Group(name="admin") db_session.add(group) company = Company(name="My company") db_session.add(company) db_session.commit() UserForm = model_form(User, db_session, exclude=['password']) class UserForm(UserForm): # Embeds OneToOne as FormField profile = wtforms.FormField( model_form(Profile, db_session, exclude=['user'], base_class=wtforms.Form)) class UserModule(ModelAdminModule): model = User db_session = db_session profile_alias = aliased(Profile)
return '<Group %r>' % self.name db.drop_all() db.create_all() group = Group(name="admins") db_session.add(group) company = Company(name="Level 2 Designs",zone=1,main_phone='714-783-6369',account_num="4565") user = User(username="******",zone=1,account_num="222",email="*****@*****.**",password="******",is_active=True) db_session.add(user) db_session.add(company) db_session.commit() UserForm = model_form(User, db_session)#,exclude=['password']) CompanyForm = model_form(Company, db_session, exclude=['main_contact_id','date_modified']) class UserForm(UserForm): # Embeds OneToOne as FormField profile = wtforms.FormField( model_form(Profile, db_session, exclude=['user'], base_class=wtforms.Form)) class UserModule(ModelAdminModule): model = User db_session = db_session profile_alias = aliased(Profile)
id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), unique=True, nullable=False) users = db.relationship("User", secondary=user_group, backref=db.backref("groups", lazy="dynamic")) def __unicode__(self): return unicode(self.name) def __repr__(self): return "<Group %r>" % self.name db.create_all() UserForm = model_form(User, db_session, exclude=["password"]) class UserForm(UserForm): """Embeds OneToOne has FormField.""" profile = wtforms.FormField(model_form(Profile, db_session, exclude=["user"], base_class=wtforms.Form)) class UserModule(ModelAdminModule): model = User db_session = db_session profile_alias = aliased(Profile) list_fields = OrderedMultiDict( (