You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please be gentle, i'm a network admin, who's having a go 'programming' ;)
To the point.
When i specify a custom view class in my model, default form_create_rules inherited from 'flask.ext.admin.form.rules' seem to get overridden. As i now need to explicitly set a primary key, when
i create a new record, via the sandman admin interface.
Not specifying a custom 'view' results in the default behaviour, of not needing to specify a primary
key upon record creation.
I hope the i'm no being to cryptic.
my models as exposed to sandman
from sandman.model import register, activate, Model
from flask.ext.admin.contrib.sqla import ModelView
from sandman import db
class ViewVlan(View):
column_list = ('name', 'tag', 'interface', 'ip', 'relatienr', 'comment')
class Vlan(Model):
__tablename__ = 'vlan'
__view__ = ViewVlan
def __str__(self):
return self.name
class Interface(Model):
__tablename__ = 'interface'
def __str__(self):
return self.name
class Switch(Model):
__tablename__ = 'switch'
def __str__(self):
return self.name
register((Vlan, Interface, Switch))
activate(admin=True, browser=False)
flask-sqlalchemy model
#!/usr/bin/env python
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite+pysqlite:///kiba.db'
app.config['DEBUG'] = True
db = SQLAlchemy(app)
class Switch(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.Unicode, unique=True)
class Interface(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.Unicode)
vlan_id = db.Column(db.Integer, db.ForeignKey('vlan.id'))
patch = db.Column(db.Text(1024))
comment = db.Column(db.Text(1024))
class Vlan(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.Unicode)
tag = db.Column(db.Integer)
intefaces = db.relationship('Interface', backref='vlan', lazy='dynamic')
ip = db.Column(db.Text(1024))
comment = db.Column(db.Text(1024))
relatienr = db.Column(db.Text(1024))
db.create_all()
Thanks,
Tim
The text was updated successfully, but these errors were encountered:
Hello,
Please be gentle, i'm a network admin, who's having a go 'programming' ;)
To the point.
When i specify a custom view class in my model, default form_create_rules inherited from 'flask.ext.admin.form.rules' seem to get overridden. As i now need to explicitly set a primary key, when
i create a new record, via the sandman admin interface.
Not specifying a custom 'view' results in the default behaviour, of not needing to specify a primary
key upon record creation.
I hope the i'm no being to cryptic.
my models as exposed to sandman
flask-sqlalchemy model
Thanks,
Tim
The text was updated successfully, but these errors were encountered: