Django admin for non Django ORM
Project description
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
- 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')
- 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)
- Collect static
python -m solo_django_admin.manage collectstatic --settings=path_to_settings
- 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
- Create superuser
python -m solo_django_admin.manage createsuperuser
- 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__':
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solo_django_admin-0.1.4.tar.gz.
File metadata
- Download URL: solo_django_admin-0.1.4.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05d688a12912133a5221b162b03f92c3f1d3e3d65c67ac268a8b00d3567ff312
|
|
| MD5 |
2da32c23dd7f386c2059d8a86fc34a78
|
|
| BLAKE2b-256 |
7b502398735e75f94c791cf3b38de0d10302423b4c60766e61379ce6aba4e45f
|
File details
Details for the file solo_django_admin-0.1.4-py3-none-any.whl.
File metadata
- Download URL: solo_django_admin-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
608335b6c908a0fde41410ab9bce9a527ed34bc469697c2c3a3856d937dc7fb9
|
|
| MD5 |
a576fd5ed1855e8a745fe9ab5762696d
|
|
| BLAKE2b-256 |
bc34878ee41fd8ebb289723c690fa713ebfdb3e3b87e2343147cf86d1b941f17
|