### Install django-q2 and Run Worker Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/bulk_edit_async.md Install the django-q2 package, apply its migrations, and start the worker process. Ensure django_q is in INSTALLED_APPS. ```bash pip install django-q2 python manage.py migrate django_q python manage.py qcluster # run this in a separate process ``` -------------------------------- ### Build and Start Docker Environment Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/README.md Use this command to build Docker images, start services, and enter the Django container for development. ```bash ./runproj up ``` -------------------------------- ### Example Usage Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/poweractions.md Demonstrates how to create and use PowerButton instances. ```APIDOC ## Example Usage ### Creating a basic PowerButton ```python SELECTED_MODAL = PowerButton( text="Selected Summary", url_name="sample:book-selected-summary", display_modal=True, uses_selection=True, selection_min_count=1, selection_min_behavior="disable", selection_min_reason="Select at least one row first.", permission_check="can_use_selected_summary", permission_behavior="hide", ) extra_buttons = [ SELECTED_MODAL, SELECTED_MODAL.with_options( text="Selected Summary (Do Not Clear)", clear_selection_on_success=False, ), SELECTED_MODAL.with_options( text="Selected Export", url_name="sample:book-selected-export", modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-7xl flex-col", selection_min_reason="Select at least one row to export.", ), ] ``` ``` -------------------------------- ### Quick Start Docker Commands Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Use these commands to quickly start, migrate, and run the Django development server within the Dockerized environment. Remember to stop containers with `./runproj down` when finished. ```bash ./runproj up # Start all containers (drops you into Django container) ./manage.py migrate # Set up database ./rs # Start Django server (in separate terminal: ./runproj exec) ``` -------------------------------- ### Start Development Environment Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Builds and starts all necessary Docker containers for development, including Django, PostgreSQL, Redis, and Vite. Automatically places you inside the Django container. ```bash ./runproj up ``` -------------------------------- ### Configure Redis Cache Backend Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/bulk_edit_async.md An example configuration for using Redis as the cache backend for asynchronous operations. Ensure django-redis is installed. ```python CACHES = { "powercrud_async": { "BACKEND": "django_redis.cache.RedisCache", "LOCATION": f"redis://:{REDIS_PASSWORD}@redis.example.com:6379/3", "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", "SERIALIZER": "django_redis.serializers.json.JSONSerializer", }, "KEY_PREFIX": "powercrud", "TIMEOUT": None, }, } ``` -------------------------------- ### Start Async Task Processor Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Starts the `django-q2` async task processor. This command should be run in a separate terminal after entering the Django container. ```bash ./manage.py qcluster ``` -------------------------------- ### Start Django-Q2 Async Task Processor Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Use this command inside the Django container to start the asynchronous task processor for Django-Q2. ```bash # In Django container ./manage.py qcluster # Start async task processor ``` -------------------------------- ### PowerAction with Options Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/poweractions.md Example of creating a PowerAction and customizing it using `with_options`. ```APIDOC ## PowerAction with Options `to_dict()` returns the base `extra_actions` dictionary. `with_options(...)` returns a new `PowerAction` with selected values changed. Any constructor parameter in the table above can be passed to `with_options(...)`. ```python ROW_MODAL = PowerAction( text="Workflow Action", url_name="cases:workflow-action", display_modal=True, modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-5xl flex-col", hidden_if="should_hide_workflow_action", hidden_if_mode="lazy", disabled_state="get_workflow_action_disabled_state", disabled_state_mode="lazy", permission_check="can_run_workflow_action", permission_behavior="hide", ) extra_actions = [ ROW_MODAL, ROW_MODAL.with_options( text="Timeline", url_name="cases:timeline", modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-7xl flex-col", disabled_state=None, ), ] ``` ``` -------------------------------- ### Start Django Development Server Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Launches the Django development server. This is a shortcut for './manage.py runserver 0:8001'. ```bash ./rs ``` -------------------------------- ### Install Python Packages Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/getting_started.md Install the core Django PowerCRUD package and its primary dependency, neapolitan, using pip. ```bash pip install neapolitan pip install django-powercrud ``` -------------------------------- ### Base Configuration API Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/index.md Use the Base Configuration API for simpler views or when direct mapping to configuration is desired. This example shows defining fields directly as class attributes. ```python class BookCRUDView(PowerCRUDMixin, CRUDView): model = Book fields = ["title", "author", "status"] form_fields = ["title", "author", "status"] inline_edit_fields = ["status"] bulk_fields = ["status"] ``` -------------------------------- ### Install Core Suite with Django 5.2 Constraints Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Install the core test suite for Django 5.2 using a specific constraints file to ensure compatibility. ```bash # Django 5.2 core suite uv pip install -c requirements/constraints-django52.txt ".[tests-core]" pytest -m "not playwright" ``` -------------------------------- ### Install Core Suite with Django 6.0 Constraints Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Install the core test suite for Django 6.0 using a specific constraints file to ensure compatibility. ```bash # Django 6.0 core suite uv pip install -c requirements/constraints-django60.txt ".[tests-core]" pytest -m "not playwright" ``` -------------------------------- ### Install Full Playwright Suite with Django 6.0 Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Install dependencies for the full Playwright suite with Django 6.0, including UI components and building assets. ```bash # Django 6.0 full Playwright suite uv pip install -c requirements/constraints-django60.txt ".[tests-core]" ".[tests-ui]" npm ci npm run build pytest -m playwright ``` -------------------------------- ### Order By Configuration Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/forms.md Shows how to specify a field to sort the child queryset by after filtering. ```python "order_by": "name" ``` -------------------------------- ### Async Bulk Operations (Opt-in) Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/README.md This example shows explicit async queueing using `PowerCRUDAsyncMixin` and `bulk_async`. Ensure django-q2 is configured. ```python from neapolitan.views import CRUDView from powercrud.mixins import PowerCRUDAsyncMixin class ProjectAsyncCRUDView(PowerCRUDAsyncMixin, CRUDView): model = Project base_template_path = "core/base.html" bulk_fields = ["status", "owner"] bulk_delete = True bulk_async = True bulk_min_async_records = 20 bulk_async_conflict_checking = True # Optional async dashboard manager async_manager_class_path = "myapp.async_manager.AppAsyncManager" ``` -------------------------------- ### Install Playwright Browser Dependencies Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Install the necessary browser binaries for Playwright to run tests. This is required if not running within a Docker image that already has them. ```bash playwright install chromium ``` -------------------------------- ### Set Up Django Application Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Executes Django's database migration commands within the running Django container. Ensure you have already started the development environment. ```bash # You're now inside the Django container ./manage.py makemigrations ./manage.py migrate ``` -------------------------------- ### PowerButton with Permissions Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/poweractions.md Demonstrates a PowerButton configured with permission checks. This ensures the button is only visible or usable based on user capabilities. ```python PowerButton( text="Selected Summary", url_name="sample:book-selected-summary", display_modal=True, uses_selection=True, selection_min_count=1, selection_min_behavior="disable", selection_min_reason="Select at least one row first.", permission_check="can_use_selected_summary", permission_behavior="hide", ) def can_use_selected_summary(self, request, obj=None): return request.user.has_perm("sample.view_selected_summary") ``` -------------------------------- ### Static Filters Configuration Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/forms.md Illustrates how to apply fixed, always-on filters to a child field's queryset. ```python "static_filters": {"side__in": ["analytics", "both"]} ``` -------------------------------- ### Install Playwright Smoke Subset with Django 5.2 Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Install dependencies for the Playwright smoke subset with Django 5.2, including UI components and building assets. ```bash # Django 5.2 Playwright smoke subset uv pip install -c requirements/constraints-django52.txt ".[tests-core]" ".[tests-ui]" npm ci npm run build pytest -m playwright_smoke ``` -------------------------------- ### Empty Behavior Configuration Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/forms.md Demonstrates setting the behavior for child querysets when a parent field's value is empty. ```python "empty_behavior": "none" ``` -------------------------------- ### Define and Use PowerAction with Options Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/poweractions.md Example of defining a PowerAction with specific modal and conditional display/disable states, and using `with_options` to create a variant. ```python ROW_MODAL = PowerAction( text="Workflow Action", url_name="cases:workflow-action", display_modal=True, modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-5xl flex-col", hidden_if="should_hide_workflow_action", hidden_if_mode="lazy", disabled_state="get_workflow_action_disabled_state", disabled_state_mode="lazy", permission_check="can_run_workflow_action", permission_behavior="hide", ) extra_actions = [ ROW_MODAL, ROW_MODAL.with_options( text="Timeline", url_name="cases:timeline", modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-7xl flex-col", disabled_state=None, ), ] ``` -------------------------------- ### Minimal Setup for List Options Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/list_options.md Enables list options by setting `list_options_enabled = True`. All defined fields and properties are visible by default. ```python class ProjectCRUDView(PowerCRUDMixin, CRUDView): model = Project fields = [ "reference", "owner", "status", "needs_attention", "due_date", "internal_notes", ] properties = ["is_overdue"] list_options_enabled = True ``` -------------------------------- ### Invalid mixed configuration example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/powerfields.md Demonstrates an invalid configuration where Base Configuration API attributes and power_fields are mixed in the same view. ```python class BookView(PowerCRUDAsyncMixin, CRUDView): model = Book fields = ["title", "author"] power_fields = [ PowerField("title", inline=True), ] ``` -------------------------------- ### Basic CRUD View Setup Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/getting_started.md Define a basic CRUD view by inheriting from PowerCRUDMixin and CRUDView. Specify the model, fields, and base template path. ```python from powercrud.mixins import PowerCRUDMixin from neapolitan.views import CRUDView from . import models class ProjectCRUDView(PowerCRUDMixin, CRUDView): model = models.Project fields = ["name", "owner", "last_review", "status"] base_template_path = "core/base.html" ``` -------------------------------- ### Non-Workable Annotation Declarations Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/queryset_annotation_fields.md Examples of configurations that fail due to naming mismatches, missing annotations, or invalid field usage. ```python queryset = Action.objects.annotate(_analytics_status_ok=Case(...)) fields = ["analytics_status_ok"] ``` ```python fields = ["analytics_status_ok"] ``` ```python fields = ["analytics_status_ok"] inline_edit_fields = ["analytics_status_ok"] ``` ```python queryset = Action.objects.annotate(analytics_status_ok=Value(None)) filterset_fields = ["analytics_status_ok"] ``` -------------------------------- ### Configure temporal list columns Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/powerfields.md Example of using value_format within the column dictionary to control date and time display in list views. ```python class TaskCRUDView(PowerCRUDMixin, CRUDView): model = Task default_datetime_value_format = "date" # Package default; optional here. power_fields = [ PowerField("created_at", default_list=True), PowerField( "updated_at", default_list=True, column={"value_format": "time"}, ), PowerField( "completed_at", default_list=True, column={"value_format": "datetime"}, ), ] ``` -------------------------------- ### Copy All CRUD Templates for Book Model Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/mgmt_commands.md Example of using `pcrud_mktemplate` with the `--all` option to copy all CRUD templates for a specific model, in this case, the `Book` model from the `library` app. ```bash python manage.py pcrud_mktemplate library.Book --all ``` -------------------------------- ### Copy List Template for Book Model Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/mgmt_commands.md Example of using `pcrud_mktemplate` with the `--list` option to copy only the list template for the `Book` model from the `library` app. ```bash python manage.py pcrud_mktemplate library.Book --list ``` -------------------------------- ### Base API vs PowerAction Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/poweractions.md Compare the traditional Base API dictionary shape for extra actions with the more reusable PowerAction declaration. Use PowerAction when related views repeat the same action mechanics. ```python extra_actions = [ { "text": "Workflow Action", "url_name": "cases:workflow-action", "needs_pk": True, "display_modal": True, "modal_box_classes": "modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-5xl flex-col", "hidden_if": "should_hide_workflow_action", "disabled_state": "get_workflow_action_disabled_state", }, { "text": "Timeline", "url_name": "cases:timeline", "needs_pk": True, "display_modal": True, "modal_box_classes": "modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-5xl flex-col", }, ] ``` ```python ROW_MODAL = PowerAction( text="Workflow Action", url_name="cases:workflow-action", display_modal=True, modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-5xl flex-col", hidden_if="should_hide_workflow_action", disabled_state="get_workflow_action_disabled_state", ) extra_actions = [ ROW_MODAL, ROW_MODAL.with_options( text="Timeline", url_name="cases:timeline", disabled_state=None, ), ] ``` -------------------------------- ### Run Raw Pytest (Advanced) Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Execute all tests using pytest with a specific Django settings module. Requires manual setup of assets and dependencies. ```bash # raw pytest (advanced): runs everything with DJANGO_SETTINGS_MODULE=tests.settings # You are responsible for building assets and having django-q2/qcluster/browsers available. pytest ``` -------------------------------- ### Run Full Playwright UI Suite Locally Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Execute the complete Playwright UI test suite locally. This requires built assets and browser dependencies to be installed. ```bash # full Playwright UI suite locally (requires built assets + browser deps) uv sync --group tests-core --group tests-ui npm ci npm run build pytest -m playwright ``` -------------------------------- ### Structured API PowerButton Configuration Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/permission_aware_affordances.md Configure toolbar buttons using the `PowerButton` class in the structured API. This example mirrors the base API configuration for a permission-aware button with selection logic. ```python PowerButton( text="Selected Summary", url_name="cases:selected-summary", uses_selection=True, selection_min_count=1, selection_min_behavior="disable", selection_min_reason="Select at least one case first.", permission_check="can_use_selected_summary", permission_behavior="hide", ) def can_use_selected_summary(self, request, obj=None): return CasePermissionService.can_manage_cases(request.user) ``` -------------------------------- ### Populate sample data Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/sample_app.md Run the custom management command to seed the database with initial records. ```bash ./manage.py create_sample_data ``` -------------------------------- ### Creating and Configuring PowerButtons Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/poweractions.md Demonstrates how to create a base PowerButton and then use `with_options` to create variations with different configurations, such as modifying text, modal behavior, and selection handling. ```python SELECTED_MODAL = PowerButton( text="Selected Summary", url_name="sample:book-selected-summary", display_modal=True, uses_selection=True, selection_min_count=1, selection_min_behavior="disable", selection_min_reason="Select at least one row first.", permission_check="can_use_selected_summary", permission_behavior="hide", ) extra_buttons = [ SELECTED_MODAL, SELECTED_MODAL.with_options( text="Selected Summary (Do Not Clear)", clear_selection_on_success=False, ), SELECTED_MODAL.with_options( text="Selected Export", url_name="sample:book-selected-export", modal_box_classes="modal-box flex max-h-[calc(100dvh-2rem)] w-11/12 max-w-7xl flex-col", selection_min_reason="Select at least one row to export.", ), ] ``` -------------------------------- ### Run Migrations Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/filter_favourites.md After adding the app, run Django migrations to create the necessary database tables. ```bash python manage.py migrate ``` -------------------------------- ### Install Playwright Smoke Subset with Django 6.0 Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/testing.md Install dependencies for the Playwright smoke subset with Django 6.0, including UI components and building assets. ```bash # Django 6.0 Playwright smoke subset uv pip install -c requirements/constraints-django60.txt ".[tests-core]" ".[tests-ui]" npm ci npm run build pytest -m playwright_smoke ``` -------------------------------- ### Generate Sample Data via Management Command Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/sample_app.md Use these commands to populate the database with authors and books. Supports custom counts and distribution ratios. ```bash # Create default authors (25) and books (50) ./manage.py create_sample_data # Create 100 authors and 1000 books ./manage.py create_sample_data --authors 100 --books 1000 # Create 500 books with an average of 5 books per author ./manage.py create_sample_data --books 500 --books-per-author 5 ``` -------------------------------- ### Prepare a Prerelease Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Prepares a prerelease (e.g., alpha, beta) using the same release script, specifying the prerelease type. ```bash ./new_release.sh --prepare minor --prerelease alpha ``` -------------------------------- ### Publish a New Release Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Publishes a prepared release from the host shell, triggering PyPI and documentation workflows. Assumes `--prepare` has been run. ```bash ./new_release.sh --publish ``` -------------------------------- ### Structured Declaration API Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/index.md Use the Structured Declaration API when repeated field intent becomes complex. This example defines a reusable PowerField for 'status' and uses it within the view. ```python from powercrud.powerfields import PowerField STATUS_FIELD = PowerField( "status", default_list=True, form=True, inline=True, bulk=True, ) class BookCRUDView(PowerCRUDMixin, CRUDView): model = Book power_fields = [ PowerField("title", default_list=True, form=True), PowerField("author", default_list=True, form=True), STATUS_FIELD, ] ``` -------------------------------- ### Run database migrations Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/sample_app.md Execute the standard Django migration command to prepare the database schema. ```bash ./manage.py migrate ``` -------------------------------- ### Sample App Path Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/queryset_annotation_fields.md The location of the sample application demonstrating annotated field usage. ```text /sample/annotated-book/ ``` -------------------------------- ### Install Favourites App Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/filter_favourites.md Add the favourites contrib app to your Django project's INSTALLED_APPS setting. ```python # settings.py INSTALLED_APPS = [ # ... "powercrud.contrib.favourites", ] ``` -------------------------------- ### Define a valid PowerField view Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/powerfields.md Example of a valid view configuration using the power_fields attribute exclusively. ```python class BookView(PowerCRUDAsyncMixin, CRUDView): model = Book namespace = "sample" use_htmx = True use_modal = True power_fields = [ PowerField("title", default_list=True, form=True), ] ``` -------------------------------- ### Depends On Configuration Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/forms.md Shows how to specify parent fields that a child field's queryset depends on. ```python "depends_on": ["author"] ``` -------------------------------- ### Compare Base Configuration and PowerField defaults Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/powerfields.md Comparison between legacy base configuration and the PowerField approach for broad field inclusion. ```python fields = "__all__" exclude = ["description"] detail_fields = "__all__" ``` ```python power_fields = [ PowerOverride(list="__all__", detail="__all__"), PowerField("description", exclude={"list": True}), ] ``` -------------------------------- ### Tailwind CSS Configuration with Safelist Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/mgmt_commands.md Example of how to integrate the generated Tailwind safelist JSON file into your `tailwind.config.js` file. ```javascript module.exports = { content: [ // your content paths ], safelist: require('./config/powercrud_tailwind_safelist.json') } ``` -------------------------------- ### Prepare a New Release Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/dockerised_dev.md Prepares for a new release by creating a release branch and performing necessary validation and build steps within the dev container. Supports patch, minor, or major releases, and prereleases. ```bash git switch main git pull --ff-only origin main ./new_release.sh --prepare patch # Review and edit CHANGELOG.md on release/. ./new_release.sh --publish ``` -------------------------------- ### Regular View to Start Rebuild Task Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/async_manager.md Initiates a custom asynchronous task from a regular Django view for a specific object. ```python def start_rebuild(request, pk): project = get_object_or_404(Project, pk=pk) launch_custom_task(user=request.user, affected_objects=[project]) return redirect("project-dashboard") ``` -------------------------------- ### Configure collapsed screen help Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/setup_core_crud.md Renders a daisyUI disclosure component for longer, optional guidance. ```python class ProjectCRUDView(PowerCRUDMixin, CRUDView): # … view_help = { "summary": "About this screen", "details": ( "Use this screen to review active projects.\n\n" "Inline fields can be edited directly from the table." ), "color": "info", } ``` -------------------------------- ### Include application URLs in project configuration Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/setup_core_crud.md Mount the application URLs into the main project URL configuration. ```python # config/urls.py from django.urls import include, path urlpatterns = [ path("projects/", include("myapp.urls")), ] ``` -------------------------------- ### Example of a CRUD View Identity Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/list_options.md Illustrates the Python identity string used to scope session state for column choices. ```text package.module.ProjectCRUDView ``` -------------------------------- ### Find PowerCRUD Package Path Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/styling_tailwind.md Use the Django shell to determine the exact installation path of the PowerCRUD package for Tailwind configuration. ```python python manage.py shell >>> import powercrud >>> powercrud.__path__ ['/venv/lib/python3.13/site-packages/powercrud'] ``` -------------------------------- ### Filter By Mapping Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/forms.md Demonstrates the mapping within 'filter_by', showing how a child queryset lookup relates to a parent form field. ```python "filter_by": {"authors": "author"} ``` -------------------------------- ### Set list view helper text Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/setup_core_crud.md Adds plain-text instructions directly below the list heading. ```python class ProjectCRUDView(PowerCRUDMixin, CRUDView): # … view_instructions = "Use the table below to review and update active projects." ``` -------------------------------- ### Open PowerCRUD Documentation Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/mgmt_commands.md Execute `pcrud_help` to open the official Django PowerCRUD documentation in your default web browser. ```bash python manage.py pcrud_help ``` -------------------------------- ### Dependent Queryset Configuration Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/forms.md Defines dependent queryset behavior for the 'genres' field, watching the 'author' field and filtering by 'authors' lookup. ```python field_queryset_dependencies = { "genres": { "depends_on": ["author"], "filter_by": {"authors": "author"}, "order_by": "name", "empty_behavior": "all", } } ``` -------------------------------- ### Custom User Resolver Example 1 Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/advanced/filter_favourites.md Implement a custom user resolver function that returns the user from `request.original_operator` or falls back to `request.user`. ```python # myapp/powercrud.py def resolve_filter_favourite_user(request): """Return the user who should own saved PowerCRUD filter favourites.""" return getattr(request, "original_operator", None) or request.user ``` -------------------------------- ### inline_edit_allowed Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/hooks.md Use this when some rows should stay read-only inline even though inline editing is enabled for the view overall, for example archived or workflow-locked records. ```APIDOC ## inline_edit_allowed(request, obj) ### Description Use this when some rows should stay read-only inline even though inline editing is enabled for the view overall, for example archived or workflow-locked records. ### Method Python method override ### Endpoint N/A ### Parameters - **request** (HttpRequest) - The current request object. - **obj** (Model) - The object instance. ### Request Example ```python def inline_edit_allowed(self, request, obj): return obj.status != 'locked' ``` ### Response #### Success Response - **allowed** (bool) - True if inline editing is allowed for the object, False otherwise. ``` -------------------------------- ### get_filter_queryset_for_field() Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/reference/hooks.md Use this when a filter-form dropdown should not show every possible related record, for example when you only want active owners, visible categories, or tenant-scoped choices. ```APIDOC ## get_filter_queryset_for_field(field, request, queryset) ### Description Use this when a filter-form dropdown should not show every possible related record, for example when you only want active owners, visible categories, or tenant-scoped choices. ### Method Python method override ### Endpoint N/A ### Parameters - **field** - The filter field object. - **request** (HttpRequest) - The current request object. - **queryset** (QuerySet) - The initial queryset for the filter. ### Request Example ```python def get_filter_queryset_for_field(self, field, request, queryset): if field.name == 'owner': return queryset.filter(is_active=True) return queryset ``` ### Response #### Success Response - **queryset** (QuerySet) - The filtered queryset for the filter field. ``` -------------------------------- ### Mixing Base API with Structured Actions/Buttons Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/structured_api/index.md Demonstrates how to mix Base API dictionaries with Structured API elements like PowerAction and PowerButton within `extra_actions`. ```python extra_actions = [ ROW_PREVIEW, { "url_name": "library:book-history", "text": "History", "display_modal": True, }, ] ``` -------------------------------- ### Sample App: Dynamic Inline Field Overrides Example Source: https://github.com/doctor-cornelius/django-powercrud/blob/main/docs/mkdocs/guides/inline_editing.md Demonstrates the pattern for parent/child dropdowns that refresh inline using `field_queryset_dependencies` and a custom `form_class`. ```python class BookCRUDView(PowerCRUDMixin, CRUDView): model = Book form_class = BookForm field_queryset_dependencies = { "genres": { "depends_on": ["author"], "filter_by": {"authors": "author"}, "order_by": "name", "empty_behavior": "all", } } use_htmx = True inline_edit_fields = [ "title", "author", "genres", "published_date", "bestseller", "isbn", "description", ] ``` ```python class BookForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["genres"].required = False ```