Adding foreign key to auto forms
This commit is contained in:
@@ -2,16 +2,17 @@ from uuid import UUID, uuid4
|
||||
from enum import Enum
|
||||
|
||||
from sqlmodel import Field, SQLModel, select
|
||||
from pydantic import Field as PydField
|
||||
|
||||
from category.models import CategoryRead
|
||||
|
||||
|
||||
class AccountType(Enum):
|
||||
|
||||
Asset = "Asset" # < Denotes a generic asset account.
|
||||
Checkings = "Checkings" # < Standard checking account
|
||||
Savings = "Savings" # < Typical savings account
|
||||
Cash = "Cash" # < Denotes a shoe-box or pillowcase stuffed with cash
|
||||
|
||||
Liability = "Liability" # < Denotes a generic liability account.
|
||||
CreditCard = "CreditCard" # < Credit card accounts
|
||||
Loan = "Loan" # < Loan and mortgage accounts (liability)
|
||||
@@ -69,10 +70,19 @@ class Account(AccountBaseId, table=True):
|
||||
session.commit()
|
||||
|
||||
class AccountRead(AccountBaseId):
|
||||
default_category: CategoryRead
|
||||
# default_category: CategoryRead
|
||||
pass
|
||||
|
||||
class AccountWrite(AccountBase):
|
||||
pass
|
||||
default_category_id: UUID = PydField(default=None, json_schema_extra={
|
||||
"foreign_key": {
|
||||
"reference": {
|
||||
"resource": "categories",
|
||||
"schema": "CategoryRead",
|
||||
"label": "name"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
class AccountCreate(AccountWrite):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user