Skip to content

Instantly share code, notes, and snippets.

@libbkmz
Created August 19, 2013 14:08
Show Gist options
  • Select an option

  • Save libbkmz/6269524 to your computer and use it in GitHub Desktop.

Select an option

Save libbkmz/6269524 to your computer and use it in GitHub Desktop.
class CategoryForm(BaseForm):
name = TextField("Category Name: ")
description = TextAreaField("Category description: ")
# child = Select2Field("ChildCats: ", coerce=int)
# parent_id = Select2TagsField("ChildCats: ", )
parent_id = SelectMultipleField("ChildCats: ", coerce=int)
class CategoryModelView(View):
column_exclude_list = ('master_key', 'IV', 'test_passphrase')
form_excluded_columns = ('master_key', 'IV', 'test_passphrase')
edit_form = CategoryForm
# can_create = False
# def edit_form(self, obj=None):
# assert False
# form = self.form
def edit_form(self, obj=None):
form = CategoryForm(obj=obj)
form.parent_id.choices = [
(p.id, p.name)
for p in Category.query.filter(
Category.parent_id == obj.id
).all()
]
# assert False
form.parent_id.data = [ p.id for p in obj.child ]
# import pdb; pdb.set_trace()
return form
def on_model_change(self, form, model):
assert False
print 12312312312312312
pass
def after_model_change(self, form, model, is_created):
print 11111111111111111
def __init__(self, session, **kwargs):
super(CategoryModelView, self).__init__(Category, session, **kwargs)
class Category(db.Model):
__tablename__ = "categories"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(255), unique=False)
description = db.Column(db.Text, )
parent_id = db.Column(db.Integer, db.ForeignKey('categories.id'), default=0)
child = db.relationship("Category",
remote_side=[id],
# backref=db.backref('children'),
# backref='children',
backref=db.backref('children', lazy='dynamic'),
)
master_key = db.Column(db.Binary(), )
IV = db.Column(db.Binary(), )
test_passphrase = db.Column(db.String(), )
passwords = db.relationship("Password",
backref='passwords',
)
def __init__(self, **kwargs):
super(Category, self).__init__(**kwargs)
def __repr__(self):
return u"[Category: %s]" % self.name
def __unicode__(self):
return u"[Category: %s]" % self.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment