Skip to content

Admin interface

You can go read on ecodev-core for more information on Sqladmin. It is a very simple to use library that does the equivalent of the Django Admin interface.

Set up thanks to the app entry point, you get ouf of the box a login screen for this admin interface

Admin login screen

Admin login screen

When loggged in, you can modify all table entries corresponding to views that you defined in admin.py (as you can see, it is an easy thing to do 😊)

Admin table view

Admin table view

And to edit an entry, simply click on thre corresponding icon to gtet the following screen

Admin entry view

Admin entry view

The different fields to edit correspond to the ones defined in the SQLModel class

"""
Module implementing an example sql table/python class (alchemy handled by sql...model :))
"""
from datetime import datetime

from sqlmodel import Field
from sqlmodel import SQLModel

from app.domain_model import ProductType


class ProductBase(SQLModel):  # type: ignore
    """
    Example base class. See
    https://sqlmodel.tiangolo.com/tutorial/fastapi/multiple-models/
    for good practice examples.
    """

    id: int | None = Field(default=None, primary_key=True)
    type: ProductType
    name: str
    value: float


class Product(ProductBase, table=True):  # type: ignore
    """
    Example sql table/python class
    """
    __tablename__ = 'product'
    id: int | None = Field(default=None, primary_key=True)
    created_at: datetime = Field(default_factory=datetime.utcnow)

Here ProductType is an Enum

"""
Module implementing an example enum
"""
from enum import Enum
from enum import unique


@unique
class ProductType(str, Enum):
    """
    Example enum
    """
    TECHNOLOGY = 'Technology'
    FOOD = 'Food'
    HEALTH = 'Health'

and interpreted like so by sqladmin as you can see on the sqladmin entry view 😊!