File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 99from datetime import datetime
1010from functools import partial
1111
12+ import sqlalchemy as sa
1213from aiohttp import web
1314from sqlalchemy .ext .asyncio import async_sessionmaker , create_async_engine
14- from sqlalchemy .orm import Mapped , mapped_column
15+ from sqlalchemy .orm import DeclarativeBase , Mapped , mapped_column
1516
1617import aiohttp_admin
17- from _models import Base , Simple , SimpleParent
1818from aiohttp_admin import Permissions , UserDetails
1919from aiohttp_admin .backends .sqlalchemy import SAResource , permission_for as p
2020
2121
22+ class Base (DeclarativeBase ):
23+ """Base model."""
24+
25+
26+ class Simple (Base ):
27+ __tablename__ = "simple"
28+
29+ id : Mapped [int ] = mapped_column (primary_key = True )
30+ num : Mapped [int ]
31+ optional_num : Mapped [float | None ]
32+ value : Mapped [str ]
33+
34+
35+ class SimpleParent (Base ):
36+ __tablename__ = "parent"
37+
38+ id : Mapped [int ] = mapped_column (sa .ForeignKey (Simple .id , ondelete = "CASCADE" ),
39+ primary_key = True )
40+ date : Mapped [datetime ]
41+
42+
2243class User (Base ):
2344 __tablename__ = "user"
2445
Original file line number Diff line number Diff line change 44"""
55
66from datetime import datetime
7+ from enum import Enum
78
9+ import sqlalchemy as sa
810from aiohttp import web
911from sqlalchemy .ext .asyncio import async_sessionmaker , create_async_engine
12+ from sqlalchemy .orm import DeclarativeBase , Mapped , mapped_column
1013
1114import aiohttp_admin
12- from _models import Base , Simple , SimpleParent
1315from aiohttp_admin .backends .sqlalchemy import SAResource
1416
17+ # Example DB models
18+
19+
20+ class Currency (Enum ):
21+ EUR = "EUR"
22+ GBP = "GBP"
23+ USD = "USD"
24+
25+
26+ class Base (DeclarativeBase ):
27+ """Base model."""
28+
29+
30+ class Simple (Base ):
31+ __tablename__ = "simple"
32+
33+ id : Mapped [int ] = mapped_column (primary_key = True )
34+ num : Mapped [int ]
35+ optional_num : Mapped [float | None ]
36+ value : Mapped [str ]
37+
38+
39+ class SimpleParent (Base ):
40+ __tablename__ = "parent"
41+
42+ id : Mapped [int ] = mapped_column (sa .ForeignKey (Simple .id , ondelete = "CASCADE" ),
43+ primary_key = True )
44+ date : Mapped [datetime ]
45+ currency : Mapped [Currency ] = mapped_column (default = "USD" )
46+
1547
1648async def check_credentials (username : str , password : str ) -> bool :
1749 return username == "admin" and password == "admin"
You can’t perform that action at this time.
0 commit comments