CRUD View Configuration
Class Attributes
class PatientCrudView(BaseCrudView):
page_title = "Patients" # shown on the page header
add_btn_title = "Add Patient" # label on the Add button (required)
table = PatientTable # your ModelTable subclass
form = PatientForm # your BaseForm subclass
page_title
The heading displayed at the top of the CRUD interface. Set it to describe the records being managed (e.g., "Patient Records", "Product Catalogue").
add_btn_title
The text on the button that opens the add form. This attribute is required — leaving it empty will cause the button to render incorrectly.
table
Your ModelTable subclass. Defines columns, sorting, search, and row actions shown in the list view.
form
Your BaseForm subclass. Used for both the Add form (triggered by the add button) and the Edit form (triggered by row actions of type "form").
Controlling the Add Button
Override display_add_button_check to conditionally show or hide the Add button per user/role:
def display_add_button_check(self, request):
# Show Add button only for Admin role
from zango.core.utils import get_current_role
role = get_current_role()
return role and role.name == "Admin"
Return True to show the button, False to hide it.
Full Example
from ...packages.crud.base import BaseCrudView
from .tables import PatientTable
from .forms import PatientForm
class PatientCrudView(BaseCrudView):
page_title = "Patient Master"
add_btn_title = "Add Patient"
table = PatientTable
form = PatientForm
def display_add_button_check(self, request):
from zango.core.utils import get_current_role
role = get_current_role()
if role:
return role.name in ["Admin", "Manager"]
return False