Admin console and project models
Enable the optional model admin, choose exposed models and fields, and manage mounted projects from one primary login.
Work through each step in order. The examples use the generated LenAPI project structure and are designed to be adapted to your app.
Enable the admin console
The optional /admin/ console is separate from protected Swagger/ReDoc docs. Enable it in settings.py, create the framework tables with migration, then create the first admin through the CLI. Admin accounts are stored in the configured database. Do not add passwords to a URL or source file.
# settings.py
ADMIN_ENABLED = True
ADMIN_URL = "/admin/"
ADMIN_MONITORING_ENABLED = True
# First setup, from the generated project directory
python lenora.py migration
python lenora.py admin
python lenora.py runKeep the admin console disabled when it is not needed. Use HTTPS in deployed environments and protect admin credentials as production secrets.
Explicitly register the models and fields to expose
Create app/admin.py and register only the models the admin should manage. fields sets the visible/editable allow-list, readonly shows a field without permitting edits, and exclude hides sensitive fields. Credential fields remain protected. The admin supports listing, reading, editing, and deleting records; create records through your app's own API or service logic.
# app/admin.py
from lenapi.admin import admin
from .models import Student, Course, Invoice, Staff
admin.register(
Student,
fields=("person_name", "course", "email", "profile_image"),
readonly=("email",),
exclude=("password", "private_notes"),
)
admin.register(Course, fields=("title", "description", "is_active"))
admin.register(
Invoice,
fields=("invoice_number", "student_id", "amount", "status"),
readonly=("invoice_number",),
exclude=("payment_token", "provider_response"),
)
admin.register(
Staff,
fields=("name", "work_email", "department"),
readonly=("work_email",),
exclude=("password", "salary", "hr_notes"),
)Grant access per model
A superadmin can create admin accounts and grant view, read, write, and delete access per model. view controls whether the model appears in navigation; read permits listing/viewing records; write permits updates; delete permits removal. Keep permissions narrow because the admin UI operates directly on registered model data.
Use one admin entry for mounted projects
When the primary app mounts sibling projects with app.mount(), its /admin/ groups registered models under each project name and runs queries through each project's own database configuration. Enable admin and create the admin login only in the primary project. In mounted projects, keep ADMIN_ENABLED=False and use their own app/admin.py files to register exposed models. The primary admin only discovers projects that are actually mounted.
# win/main.py
from lenapi import LENAPI
app = LENAPI()
app.mount("/gamer", "games")
# win/settings.py
ADMIN_ENABLED = True
# games/settings.py
ADMIN_ENABLED = False
# games/app/admin.py
from lenapi.admin import admin
from .models import Game
admin.register(Game, fields=("title", "is_published"))Mounted-project permission keys are prefixed with the project name, for example games:game. Same-named models in different projects therefore keep distinct permissions.
Optionally monitor the application process
With the admin enabled, install the monitoring extra and enable ADMIN_MONITORING_ENABLED. The page displays CPU and RAM metrics, the LenAPI process ID, and thread count. This is an on-demand operational view, not an alerting system or full host monitoring service.
python -m pip install 'lenapi[monitoring]'
# settings.py
ADMIN_ENABLED = True
ADMIN_MONITORING_ENABLED = True