Skip to main content

solo-django-admin

Django admin for non Django ORM

For now support only Tortoise ORM

https://github.com/tortoise/tortoise-orm

Install

pip install solo-django-admin

Config

  1. Create settings.py file and redefine DATABASES if needed because by default db engine is 'django.db.backends.sqlite3'
from solo_django_admin.core.settings import *

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.getenv(f'{ENV_PREFIX}_DB_NAME'),
        'USER': os.getenv(f'{ENV_PREFIX}_DB_USER'),
        'PASSWORD': os.getenv(f'{ENV_PREFIX}_DB_PASSWORD'),
        'HOST': os.getenv(f'{ENV_PREFIX}_DB_HOST'),
        'PORT': os.getenv(f'{ENV_PREFIX}_DB_PORT', default=5432)
    }
}
INSTALLED_APPS.append('YOR_APP_NAME')
  1. Create .env and/or set environments variables if needed, all values are optional
ENV_PREFIX=DJANGO_ADMIN  # by default
DJANGO_ADMIN_DEBUG=True  # default False
DJANGO_ADMIN_DJANGO_SETTINGS_MODULE=path_to_settings_file
DJANGO_ADMIN_DB_USER=postgres
DJANGO_ADMIN_DB_NAME=postgres
DJANGO_ADMIN_DB_HOST=localhost
DJANGO_ADMIN_DB_PASSWORD=postgres
DJANGO_ADMIN_DB_PORT=5432
DJANGO_ADMIN_STATIC_URL=/django-admin-static/  # by default
DJANGO_ADMIN_STATIC_ROOT=path_to_static_files
DJANGO_ADMIN_MEDIA_URL=/django-admin-media/  # by default
DJANGO_ADMIN_MEDIA_ROOT=path_to_media_files
DJANGO_ADMIN_ALLOWED_HOSTS=* # by default (example: https://site.com,localhost)
  1. Collect static
python -m solo_django_admin.manage collectstatic --settings=path_to_settings
  1. Migrate database

Attention! the following tables will be created in the database, they are necessary for the operation of the Django admin panel

auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
auth_user_user_permissions
django_admin_log
django_content_type
django_migrations
django_session
  1. Create superuser
python -m solo_django_admin.manage createsuperuser
  1. Start app

Adding models to the admin panel is no different from Django, but adding models is a little different

create your own app, for example mappers

python -m solo_django_admin.manage startapp mappers

add the same models as in your application on fastapi

models.py

from solo_django_admin.models import MapperModel
from path_to_fastapi_model import Account as FastAPIAccount

class Account(MapperModel):
    fast_api_model = FastAPIAccount

admin.py

from django.contrib import admin
from .models import Account

@admin.register(Account)
class AccountAdmin(admin.ModelAdmin):
    ...

Don`t forget add your app to settings

INSTALLED_APPS.append('mappers')


How to use FK, ManyToMany, OneToOne etc. fields see examples


Example how to connect with FastAPI

import os

from fastapi import FastAPI

from solo_django_admin.core.asgi import application
from solo_django_admin.core.settings import BASE_DIR

from starlette.middleware.cors import CORSMiddleware
from starlette.staticfiles import StaticFiles

from path_to_your_lifespan import lifespan


def create_app():
    app_ = FastAPI(lifespan=lifespan)
    app_.mount(
        "/django-admin-static",
        StaticFiles(
            directory=os.path.join(BASE_DIR, "django_admin_static_files")),
        name="static",
    )
    app_.mount("/admin", application)

    app_.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=False,
        allow_methods=["*"],
        allow_headers=["*"],
        expose_headers=["*"],
    )
    # YOUR SETTINGS HERE
    return app_


app = create_app()

if __name__ == '__main__':
    ...

Metadata

Release files for solo-django-admin 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for solo-django-admin 0.1.5
File Size Uploaded
solo_django_admin-0.1.5.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for solo-django-admin 0.1.5
File Interpreter ABI Platform
solo_django_admin-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / solo_django_admin-0.1.5.tar.gz

Download URL solo_django_admin-0.1.5.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
433848e386eff4e298b14ad256cc0c7c83df56948fb8b182ce3a8f7c16062d37
BLAKE2b-256 checksum
How to use checksums
724256f31e8520d47a52783dc77961d7f8de3725df29735ce432f5b214e00458
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / solo_django_admin-0.1.5-py3-none-any.whl

Download URL solo_django_admin-0.1.5-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ceddf29b7b5ddc180b78e37f5a02ae755d954dad068ada2867416d11bf0cfd4e
BLAKE2b-256 checksum
How to use checksums
7e8657320d516da17b21b2d6262d9ff1cda86eca9fd316604f776818b6a32f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page