Skip to main content

Inlines for sqladmin

Project description

sqladmin-inline

SQLAdmin Inline is an extension for sqladmin that brings Django-style inline editing to your SQLAlchemy models. It allows you to manage related records (one-to-many) directly within the parent model's form.

Coverage Status Coverage Status Coverage Status

Features

  • Django-style Inlines: Add, edit, and remove related records without leaving the main form.
  • Drag-and-Drop Reordering: Support for manual row reordering using SortableJS by simply defining an order_field
  • AJAX-powered "Load More": Seamlessly append more records to the list without a full page reload.
  • Bulk Actions: Integrated checkbox system for bulk deleting multiple child records at once.
  • Async & Sync Support: Fully compatible with both asynchronous and synchronous SQLAlchemy sessions.
  • Real-time Search & Pagination: Manage large datasets with AJAX-based search and paginated views.
  • Flexible Layouts: Supports modal-based editing and different positions (center or sidebar).

Installation

pip install sqladmin-inline

Full Example

Based on the provided demo.py, here is how you can set up a Post with inline Tags and Comments:

from sqladmin import Admin
from sqladmin_inline import InlineModelAdmin, ModelViewWithInlines, setup_inline_routes

# 1. Define the Inline configuration
class TagInline(InlineModelAdmin, model=Tag):
    """
    Tags — sidebar, drag-and-drop via position field.

    Features:
    - layout = "sidebar"  → displayed on the right side
    - order_field = "position" → rows are draggable,
      position updates automatically via /reorder
    - column_default_sort not needed: order_field takes priority
    - can_create = True → Add button enabled
    """

    inline_label = "Tags"
    icon = "fas fa-tag"
    layout        = "sidebar"

    # Drag-and-drop: integer order field
    order_field = "position"

    column_list = [Tag.name]  # position is shown as # automatically
    column_labels = {Tag.name: "Tag name"}
    column_searchable_list = [Tag.name]
    page_size = 5
    can_delete = True
    can_create = True
    can_edit = True
    form_excluded_columns = ["post"]


class CommentInline(InlineModelAdmin, model=Comment):
    """
    Comments — center, sorted by ID desc, FK-select for User.

    Features:
    - column_default_sort = ("id", True)  → new ones on top
    - page_size = 3 → "Load more" button appears with 4+ comments
    - can_delete = True → deletion enabled
    - can_edit = False   → no edit button
    - form_columns includes Comment.author → FK-select
    """

    inline_label = "Comments"
    icon = "fa fa-comments"
    layout = "center"

    # Sorting: new ones on top
    column_default_sort = ("id", True)

    column_list = [Comment.body, Comment.author]
    column_labels = {Comment.body: "Text", "author": "Author"}
    column_searchable_list = [Comment.body]
    page_size = 3  # intentionally small to demonstrate Load More
    can_delete = True
    can_create = True
    can_edit = True
    form_columns = [Comment.body, Comment.author]

# 2. Use ModelViewWithInlines for the parent model
class PostAdmin(ModelViewWithInlines, model=Post):
    name = "Post"
    name_plural = "Posts"
    icon = "fa-solid fa-newspaper"
    column_list = [Post.id, Post.title, Post.author]

    form_columns = [Post.title, Post.body, Post.author]
    column_labels = {Post.author: "Author", Post.title: "Title", Post.body: "Content"}

    # Tags → sidebar + drag-and-drop
    # Comments → center + sort desc + load more
    inlines = [TagInline, CommentInline]

# 3. Initialize and register
app = FastAPI()
admin = Admin(app, engine, session_maker=session_mk)

# This step is CRITICAL to register AJAX routes and templates
setup_inline_routes(admin)

admin.add_view(PostAdmin)

Configuration Reference

InlineModelAdmin Attributes

  • model: The SQLAlchemy model class (required).
  • fk_attr: Explicit foreign key attribute name (auto-detected if omitted).
  • column_list: Columns to display in the inline table.
  • column_searchable_list: Columns to include in the AJAX search.
  • layout: "center" (below form) or "sidebar" (right side).
  • can_create, can_edit, can_delete: Permissions for the inline records.
  • order_field: The name of the integer column on the model used for manual drag-and-drop ordering.
  • column_default_sort: A tuple (column_name, is_descending) to set the default list order.
  • icon: A FontAwesome or Tabler icon class string for the inline header (e.g., "fas fa-tag").
  • page_size: Number of rows displayed per page or loaded via "Load More" (default: 5).

Requirements

  • SQLAdmin >= 0.16.0
  • SQLAlchemy >= 2.0.0
  • Starlette / FastAPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqladmin_inline-0.0.4.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqladmin_inline-0.0.4-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file sqladmin_inline-0.0.4.tar.gz.

File metadata

  • Download URL: sqladmin_inline-0.0.4.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sqladmin_inline-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b639859d963efa10214ba34bbc7c553023566307a29ef004ccef72fb212bc973
MD5 1f5b54adb1575aca2affcaaeac464784
BLAKE2b-256 d5b1c4fef1624a271e524430aa3b425fc9f17536c75dd2b8b13b0b76e0c0af21

See more details on using hashes here.

File details

Details for the file sqladmin_inline-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: sqladmin_inline-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sqladmin_inline-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 514b757e6f467e8c8f82fb5edcf6c04ad87cb7c8f346a411a1497448329fc738
MD5 7ba714311d7957554b49b7ca6d3b2374
BLAKE2b-256 773f2a893de1b8d3c3ce07d1d7954a816c0f03ff571b1fa73b9fca8559891242

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page