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
I have 2 views(ContactModelView and GroupModelView) with actions and added ContactModelView as related_views in GroupModelView.
I am trying to invoke the actions of ContactModelView in GroupModelView show screen.
But, I see the action of GroupModelView is getting invoked.
view.py
from flask_appbuilder import action
from app import appbuilder
from ..model.models import Contact, ContactGroup
from flask_appbuilder import CompactCRUDMixin, ModelView
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask import redirect, render_template
class ContactModelView(ModelView):
datamodel = SQLAInterface(Contact)
label_columns = {'contact_group':'Contacts Group'}
list_columns = ['name','personal_cellphone','birthday']
show_fieldsets = [
(
'Summary',
{'fields': ['name', 'address']}
),
(
'Personal Info',
{'fields': ['birthday', 'personal_phone', 'personal_cellphone'], 'expanded': False}
),
]
@action("dispviewname", "Disp related view name", "Do you really display relatediew name?", "fa-rocket")
def myaction(self, items):
print('action in related view')
name = ''
if isinstance(items, list):
print('multi')
name = items[0].name
else:
print('single')
name = items.name
return render_template("method3.html", para3=name, base_template=appbuilder.base_template,
appbuilder=appbuilder)
@action("muldelete", "Delete", "Delete all Really?", "fa-rocket")
def muldelete(self, items):
if isinstance(items, list):
print('multi')
self.datamodel.delete_all(items)
self.update_redirect()
else:
print('single')
self.datamodel.delete(items)
return redirect(self.get_redirect())
class GroupModelView(CompactCRUDMixin, ModelView):
datamodel = SQLAInterface(ContactGroup)
show_template = "appbuilder/general/model/show_cascade.html"
list_columns = ["name", "extra_col"]
@action("dispname", "Do something on this record", "Do you really want to show?", "fa-rocket")
def showaction(self, item):
print('action in group model')
return render_template("method3.html", para3=item.name, base_template=appbuilder.base_template,
appbuilder=appbuilder)
related_views = [ContactModelView]
from flask_appbuilder import Model
from sqlalchemy import Column, Date, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
class ContactGroup(Model):
id = Column(Integer, primary_key=True)
name = Column(String(50), unique=True, nullable=False)
I am facing the issue in using show_cascade.html
I have 2 views(ContactModelView and GroupModelView) with actions and added ContactModelView as related_views in GroupModelView.
I am trying to invoke the actions of ContactModelView in GroupModelView show screen.
But, I see the action of GroupModelView is getting invoked.
view.py
from flask_appbuilder import action
from app import appbuilder
from ..model.models import Contact, ContactGroup
from flask_appbuilder import CompactCRUDMixin, ModelView
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask import redirect, render_template
class ContactModelView(ModelView):
datamodel = SQLAInterface(Contact)
class GroupModelView(CompactCRUDMixin, ModelView):
datamodel = SQLAInterface(ContactGroup)
appbuilder.add_view(
GroupModelView,
"Contact Group",
icon = "fa-envelope",
category = "Contacts"
)
appbuilder.add_view(
ContactModelView,
"List Contacts",
icon = "fa-envelope",
category = "Contacts"
)
models.py
from flask_appbuilder import Model
from sqlalchemy import Column, Date, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
class ContactGroup(Model):
id = Column(Integer, primary_key=True)
name = Column(String(50), unique=True, nullable=False)
class Contact(Model):
id = Column(Integer, primary_key=True)
name = Column(String(150), unique = True, nullable=False)
address = Column(String(564), default='Street ')
birthday = Column(Date)
personal_phone = Column(String(20))
personal_cellphone = Column(String(20))
contact_group_id = Column(Integer, ForeignKey("contact_group.id"), nullable=False)
contact_group = relationship("ContactGroup")
The text was updated successfully, but these errors were encountered: