'polymorphic_identity': 'candle',
'inherit_condition': (id == Product.id)
}
class AdministratorView(ModelView):
can_create = True
can_delete = True
can_edit = True
column_display_pk = True
def is_accessible(self):
#TODO
return True #current_user.is_authenticated and current_user.has_role("Administrateur")
def inaccessible_callback(self, name, **kwargs):
# redirect to login page if user doesn't have access
return redirect(url_for('security.login', next=request.url))
class ProductView(AdministratorView):
column_display_pk = True
column_labels = {'id':'Référence',
'name':'Désignation',
'image':'Image',
'availability':'Disponibilité',
'price':'Prix de vente',
'description':'Description du produit',
'type':'Type de produit',
'collections':'Collections'}
form_columns = ('id', 'name', 'image', 'availability', 'price', 'description', 'type')
# HERE'S THE PROBLEMATIC INSTRUCTION
inline_models = (Candle,)
admin.add_view(ProductView(Product, db.session, name='All', category='Products'))
# if i let AdministratorView, it works, but not as i want.
admin.add_view(AdministratorView(Candle, db.session, name='Candlery', category='Products'))
Could you tell me why, please ?
Edit 1 Formatting
Edit 2 Solved : in fact, after fiddling with the forms, i realised i took the problem backwards :
The Candle ModelView form manages the inheritance and does the right thing : inserting its Product part in Product, and its Candle part in Candle. No need to first create a Product, then linking a Candle to it.
I'll let this post here. In case someone, someday has the same twisted mind problem.
/r/flask
https://redd.it/6msraw
'inherit_condition': (id == Product.id)
}
class AdministratorView(ModelView):
can_create = True
can_delete = True
can_edit = True
column_display_pk = True
def is_accessible(self):
#TODO
return True #current_user.is_authenticated and current_user.has_role("Administrateur")
def inaccessible_callback(self, name, **kwargs):
# redirect to login page if user doesn't have access
return redirect(url_for('security.login', next=request.url))
class ProductView(AdministratorView):
column_display_pk = True
column_labels = {'id':'Référence',
'name':'Désignation',
'image':'Image',
'availability':'Disponibilité',
'price':'Prix de vente',
'description':'Description du produit',
'type':'Type de produit',
'collections':'Collections'}
form_columns = ('id', 'name', 'image', 'availability', 'price', 'description', 'type')
# HERE'S THE PROBLEMATIC INSTRUCTION
inline_models = (Candle,)
admin.add_view(ProductView(Product, db.session, name='All', category='Products'))
# if i let AdministratorView, it works, but not as i want.
admin.add_view(AdministratorView(Candle, db.session, name='Candlery', category='Products'))
Could you tell me why, please ?
Edit 1 Formatting
Edit 2 Solved : in fact, after fiddling with the forms, i realised i took the problem backwards :
The Candle ModelView form manages the inheritance and does the right thing : inserting its Product part in Product, and its Candle part in Candle. No need to first create a Product, then linking a Candle to it.
I'll let this post here. In case someone, someday has the same twisted mind problem.
/r/flask
https://redd.it/6msraw
reddit
[AF Flask-SQLAlchemy / Flask-Admin] Problem with... • r/flask
Hi gals & guys. 3 days i'm stuck with a problem with Flask_admin. I think i'll need something stronger than a stack of online doc and a rubber...