Answer the question
In order to leave comments, you need to log in
How to implement permissions in Flask-Admin to add users with a specific role?
I am using Flask-Admin and Flask-Security to implement the admin for my Python application. Here are the models for Role and User respectively:
class Role(db.Model, RoleMixin):
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(80), unique=True)
description = db.Column(db.String(255))
def __str__(self):
return self.name
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(255), unique=True, index=True)
password = db.Column(db.String(255))
roles = db.relationship('Role', secondary=roles_users,
backref=db.backref('users', lazy='dynamic'))
def __str__(self):
return self.username
Answer the question
In order to leave comments, you need to log in
Maybe the book "Developing Web Applications with Flask in Python" by Miguel Greenberg can help you. Chapter 9 - "User Roles". The book is available in pdf online.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question