Skip to content

Commit c17c6a9

Browse files
committed
Fix sort by and search by relations. Fix example.
1 parent 016ca6a commit c17c6a9

25 files changed

Lines changed: 4047 additions & 2081 deletions

File tree

examples/django_djangoorm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ run:
88
.PHONY: install
99
install:
1010
poetry install
11+
poetry run pip install -e ../../

examples/django_djangoorm/orm/models.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,9 @@ class BaseEventModelAdmin(DjangoModelAdmin):
139139
@register(Event)
140140
class EventModelAdmin(DjangoModelAdmin):
141141
actions = ("make_is_active", "make_is_not_active")
142-
list_display = (
143-
"id",
144-
"name_with_price",
145-
"rating",
146-
"event_type",
147-
"is_active",
148-
"started",
149-
)
142+
list_display = ("id", "tournament", "name_with_price", "rating", "event_type", "is_active", "started")
143+
list_filter = ("tournament", "event_type", "is_active")
144+
search_fields = ("name", "tournament__name")
150145

151146
@action(description="Make event active")
152147
def make_is_active(self, ids):

examples/django_djangoorm/poetry.lock

Lines changed: 37 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/django_djangoorm/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ repository = "https://github.com/vsdudakov/fastadmin"
99
package-mode = false
1010

1111
[tool.poetry.dependencies]
12-
python = "^3.10"
13-
django = "^5.2"
14-
fastadmin = {"version" = "^0.2.21", extras = ["django"]}
12+
python = "^3.13"
13+
django = "^6"
14+
fastadmin = {"version" = "^0.3.3", extras = ["django"]}
1515

1616
[build-system]
1717
requires = ["poetry-core>=1.0.0"]

examples/fastapi_ponyorm/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ all: install run
22

33
.PHONY: fastapi
44
run:
5-
poetry run fastapi dev --reload --port=8090 example.py
5+
poetry run uvicorn example:app --reload --host=0.0.0.0 --port=8090
66

77
.PHONY: install
88
install:
99
poetry install
10+
poetry run pip install -e ../../

examples/fastapi_ponyorm/example.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import os
12
import typing as tp
23
import uuid
34
from collections.abc import AsyncGenerator
45
from contextlib import asynccontextmanager
56

7+
os.environ["ADMIN_USER_MODEL"] = "User"
8+
os.environ["ADMIN_USER_MODEL_USERNAME_FIELD"] = "username"
9+
os.environ["ADMIN_SECRET_KEY"] = "secret"
10+
611
from fastapi import FastAPI
712
from fastapi.middleware.cors import CORSMiddleware
813
from models import BaseEvent, Event, Tournament, User, db
@@ -76,14 +81,9 @@ class BaseEventModelAdmin(PonyORMModelAdmin):
7681
@register(Event)
7782
class EventModelAdmin(PonyORMModelAdmin):
7883
actions = ("make_is_active", "make_is_not_active")
79-
list_display = (
80-
"id",
81-
"name_with_price",
82-
"rating",
83-
"event_type",
84-
"is_active",
85-
"started",
86-
)
84+
list_display = ("id", "tournament", "name_with_price", "rating", "event_type", "is_active", "started")
85+
list_filter = ("tournament", "event_type", "is_active")
86+
search_fields = ("name", "tournament__name")
8787

8888
@action(description="Make event active")
8989
@db_session
@@ -115,7 +115,8 @@ def name_with_price(self, obj):
115115

116116

117117
def init_db():
118-
db.bind(provider="sqlite", filename=":memory:", create_db=True)
118+
# Use shared in-memory sqlite DB so tables are visible across connections/threads.
119+
db.bind(provider="sqlite", filename=":sharedmemory:", create_db=True)
119120
db.generate_mapping(create_tables=True)
120121

121122

0 commit comments

Comments
 (0)