Skip to content

Commit 53913f0

Browse files
committed
Fixed inlines api. Fixed label fields. Fixed inlines frontend side.
1 parent 691cc5f commit 53913f0

31 files changed

Lines changed: 306 additions & 180 deletions

File tree

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pip install fastadmin[flask,sqlalchemy] # for flask with sqlalchemy
5151
```
5252

5353
for (macos) zsh use
54+
5455
```bash
5556
pip install fastadmin\[fastapi,django\]
5657
```
@@ -173,16 +174,19 @@ class User(Model):
173174
is_superuser = fields.BooleanField(default=False)
174175
is_active = fields.BooleanField(default=False)
175176
...
177+
async def __str__(self):
178+
return self.username
176179

177180

178181
class Group(Model):
179182
name = fields.CharField(max_length=255)
180183
...
184+
async def __str__(self):
185+
return self.name
181186

182187

183188
@register(User)
184189
class UserAdmin(TortoiseModelAdmin):
185-
label_fields = ("username",)
186190
exclude = ("hash_password",)
187191
list_display = ("id", "username", "is_superuser", "is_active")
188192
list_display_links = ("id", "username")
@@ -200,7 +204,6 @@ class UserAdmin(TortoiseModelAdmin):
200204

201205
@register(Group)
202206
class GroupAdmin(TortoiseModelAdmin):
203-
label_fields = ("name",)
204207
list_display = ("id", "name")
205208
list_display_links = ("id",)
206209
list_filter = ("id", "name")
@@ -212,7 +215,7 @@ class GroupAdmin(TortoiseModelAdmin):
212215
```python
213216
from django.db import models
214217

215-
from fastadmin import DjangoModelAdmin, register, sync_to_async
218+
from fastadmin import DjangoModelAdmin, register
216219

217220

218221
class User(models.Model):
@@ -221,23 +224,25 @@ class User(models.Model):
221224
is_superuser = fields.BooleanField(default=False)
222225
is_active = fields.BooleanField(default=False)
223226
...
227+
def __str__(self):
228+
return self.username
224229

225230

226231
class Group(models.Model):
227232
name = fields.CharField(max_length=255)
228233
...
234+
def __str__(self):
235+
return self.name
229236

230237

231238
@register(User)
232239
class UserAdmin(DjangoModelAdmin):
233-
label_fields = ("username",)
234240
exclude = ("hash_password",)
235241
list_display = ("id", "username", "is_superuser", "is_active")
236242
list_display_links = ("id", "username")
237243
list_filter = ("id", "username", "is_superuser", "is_active")
238244
search_fields = ("username",)
239245

240-
@sync_to_async
241246
def authenticate(self, username, password):
242247
obj = User.objects.filter(username=username, is_superuser=True).first()
243248
if not obj:
@@ -249,7 +254,6 @@ class UserAdmin(DjangoModelAdmin):
249254

250255
@register(Group)
251256
class GroupAdmin(DjangoModelAdmin):
252-
label_fields = ("name",)
253257
list_display = ("id", "name")
254258
list_display_links = ("id",)
255259
list_filter = ("id", "name")
@@ -287,16 +291,19 @@ class User(Base):
287291
is_superuser: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
288292
is_active: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
289293
...
294+
async def __str__(self):
295+
return self.username
290296

291297

292298
class Group(Base):
293299
name: Mapped[str] = mapped_column(String(length=255), nullable=False)
294300
...
301+
async def __str__(self):
302+
return self.name
295303

296304

297305
@register(User, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
298306
class UserAdmin(SqlAlchemyModelAdmin):
299-
label_fields = ("username",)
300307
exclude = ("hash_password",)
301308
list_display = ("id", "username", "is_superuser", "is_active")
302309
list_display_links = ("id", "username")
@@ -318,7 +325,6 @@ class UserAdmin(SqlAlchemyModelAdmin):
318325

319326
@register(Group, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
320327
class GroupAdmin(SqlAlchemyModelAdmin):
321-
label_fields = ("name",)
322328
list_display = ("id", "name")
323329
list_display_links = ("id",)
324330
list_filter = ("id", "name")
@@ -331,7 +337,7 @@ class GroupAdmin(SqlAlchemyModelAdmin):
331337
import bcrypt
332338
from pony.orm import Database, PrimaryKey
333339

334-
from fastadmin import PonyORMModelAdmin, register, sync_to_async
340+
from fastadmin import PonyORMModelAdmin, register
335341

336342
db = Database()
337343
db.bind(provider="sqlite", filename="db.sqlite", create_db=True)
@@ -343,27 +349,29 @@ class User(db.Entity):
343349
is_superuser = Required(bool, default=False)
344350
is_active = Required(bool, default=False)
345351
...
352+
def __str__(self):
353+
return self.username
346354

347355

348356
class Group(db.Entity):
349357
id = PrimaryKey(int, auto=True)
350358
name = Required(str)
351359
...
360+
def __str__(self):
361+
return self.name
352362

353363

354364
db.generate_mapping()
355365

356366

357367
@register(User)
358368
class UserAdmin(PonyORMModelAdmin):
359-
label_fields = ("username",)
360369
exclude = ("hash_password",)
361370
list_display = ("id", "username", "is_superuser", "is_active")
362371
list_display_links = ("id", "username")
363372
list_filter = ("id", "username", "is_superuser", "is_active")
364373
search_fields = ("username",)
365374

366-
@sync_to_async
367375
@db_session
368376
def authenticate(self, username, password):
369377
user = next((f for f in self.model_cls.select(username=username, password=password, is_superuser=True)), None)
@@ -376,7 +384,6 @@ class UserAdmin(PonyORMModelAdmin):
376384

377385
@register(Tournament)
378386
class GroupAdmin(PonyORMModelAdmin):
379-
label_fields = ("name",)
380387
list_display = ("id", "name")
381388
list_display_links = ("id",)
382389
list_filter = ("id", "name")

docs/index.html

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ <h4 class="title">FastAdmin</h4>
181181
<li class="nav-item">
182182
<a class="nav-link" href="#changelog">Changelog</a>
183183
<ul class="nav flex-column">
184+
<li class="nav-item">
185+
<a class="nav-link" href="#v0_1_25">v0.1.25</a>
186+
</li>
184187
<li class="nav-item">
185188
<a class="nav-link" href="#v0_1_24">v0.1.24</a>
186189
</li>
@@ -212,7 +215,7 @@ <h1>Documentation</h1>
212215
<div class="row">
213216
<div class="col-sm-6 col-lg-4">
214217
<ul class="list-unstyled">
215-
<li><strong>Version:</strong> 1.1.24</li>
218+
<li><strong>Version:</strong> 1.1.25</li>
216219
<li>
217220
<strong>Author:</strong>
218221
<a href="mailto:vsdudakov@gmail.com" target="_blank"
@@ -393,18 +396,20 @@ <h4>Tortoise ORM</h4>
393396
hash_password = fields.CharField(max_length=255)
394397
is_superuser = fields.BooleanField(default=False)
395398
is_active = fields.BooleanField(default=False)
396-
397399
...
400+
async def __str__(self):
401+
return self.username
398402

399403

400404
class Group(Model):
401405
name = fields.CharField(max_length=255)
402406
...
407+
async def __str__(self):
408+
return self.name
403409

404410

405411
@register(User)
406412
class UserAdmin(TortoiseModelAdmin):
407-
label_fields = ("username",)
408413
exclude = ("hash_password",)
409414
list_display = ("id", "username", "is_superuser", "is_active")
410415
list_display_links = ("id", "username")
@@ -422,7 +427,6 @@ <h4>Tortoise ORM</h4>
422427

423428
@register(Group)
424429
class GroupAdmin(TortoiseModelAdmin):
425-
label_fields = ("name",)
426430
list_display = ("id", "name")
427431
list_display_links = ("id",)
428432
list_filter = ("id", "name")
@@ -434,7 +438,7 @@ <h4>Django ORM</h4>
434438
<code class="language-python">
435439
from django.db import models
436440

437-
from fastadmin import DjangoModelAdmin, register, sync_to_async
441+
from fastadmin import DjangoModelAdmin, register
438442

439443

440444
class User(models.Model):
@@ -443,23 +447,25 @@ <h4>Django ORM</h4>
443447
is_superuser = fields.BooleanField(default=False)
444448
is_active = fields.BooleanField(default=False)
445449
...
450+
def __str__(self):
451+
return self.username
446452

447453

448454
class Group(models.Model):
449455
name = fields.CharField(max_length=255)
450456
...
457+
def __str__(self):
458+
return self.name
451459

452460

453461
@register(User)
454462
class UserAdmin(DjangoModelAdmin):
455-
label_fields = ("username",)
456463
exclude = ("hash_password",)
457464
list_display = ("id", "username", "is_superuser", "is_active")
458465
list_display_links = ("id", "username")
459466
list_filter = ("id", "username", "is_superuser", "is_active")
460467
search_fields = ("username",)
461468

462-
@sync_to_async
463469
def authenticate(self, username, password):
464470
obj = User.objects.filter(username=username, is_superuser=True).first()
465471
if not obj:
@@ -471,7 +477,6 @@ <h4>Django ORM</h4>
471477

472478
@register(Group)
473479
class GroupAdmin(DjangoModelAdmin):
474-
label_fields = ("name",)
475480
list_display = ("id", "name")
476481
list_display_links = ("id",)
477482
list_filter = ("id", "name")
@@ -509,16 +514,19 @@ <h4>SQLAlchemy ORM</h4>
509514
is_superuser: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
510515
is_active: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
511516
...
517+
async def __str__(self):
518+
return self.username
512519

513520

514521
class Group(Base):
515522
name: Mapped[str] = mapped_column(String(length=255), nullable=False)
516523
...
524+
async def __str__(self):
525+
return self.name
517526

518527

519528
@register(User, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
520529
class UserAdmin(SqlAlchemyModelAdmin):
521-
label_fields = ("username",)
522530
exclude = ("hash_password",)
523531
list_display = ("id", "username", "is_superuser", "is_active")
524532
list_display_links = ("id", "username")
@@ -540,7 +548,6 @@ <h4>SQLAlchemy ORM</h4>
540548

541549
@register(Group, sqlalchemy_sessionmaker=sqlalchemy_sessionmaker)
542550
class GroupAdmin(SqlAlchemyModelAdmin):
543-
label_fields = ("name",)
544551
list_display = ("id", "name")
545552
list_display_links = ("id",)
546553
list_filter = ("id", "name")
@@ -553,7 +560,7 @@ <h4>Pony ORM</h4>
553560
import bcrypt
554561
from pony.orm import Database, PrimaryKey
555562

556-
from fastadmin import PonyORMModelAdmin, register, sync_to_async
563+
from fastadmin import PonyORMModelAdmin, register
557564

558565
db = Database()
559566
db.bind(provider="sqlite", filename="db.sqlite", create_db=True)
@@ -566,27 +573,29 @@ <h4>Pony ORM</h4>
566573
is_superuser = Required(bool, default=False)
567574
is_active = Required(bool, default=False)
568575
...
576+
def __str__(self):
577+
return self.username
569578

570579

571580
class Group(db.Entity):
572581
id = PrimaryKey(int, auto=True)
573582
name = Required(str)
574583
...
584+
def __str__(self):
585+
return self.name
575586

576587

577588
db.generate_mapping()
578589

579590

580591
@register(User)
581592
class UserAdmin(PonyORMModelAdmin):
582-
label_fields = ("username",)
583593
exclude = ("hash_password",)
584594
list_display = ("id", "username", "is_superuser", "is_active")
585595
list_display_links = ("id", "username")
586596
list_filter = ("id", "username", "is_superuser", "is_active")
587597
search_fields = ("username",)
588598

589-
@sync_to_async
590599
@db_session
591600
def authenticate(self, username, password):
592601
user = next((f for f in self.model_cls.select(username=username, password=password, is_superuser=True)), None)
@@ -599,7 +608,6 @@ <h4>Pony ORM</h4>
599608

600609
@register(Tournament)
601610
class GroupAdmin(PonyORMModelAdmin):
602-
label_fields = ("name",)
603611
list_display = ("id", "name")
604612
list_display_links = ("id",)
605613
list_filter = ("id", "name")
@@ -914,12 +922,6 @@ <h3>ModelAdmin options</h3>
914922
<p class="lead">Specific options:</p>
915923
<pre>
916924
<code class="language-python">
917-
# Labels for model. We use them in select, autocomplete and other wigets where we represent model items.
918-
# We user first from label_fields, if it is empty, we use the second and so on.
919-
# If you don't set this attribute, we will use id attr as label.
920-
# Example of usage: label_fields = ("name", "email", "id")
921-
label_fields: Sequence[str] = ()
922-
923925
# Use list_display_links to control if and which fields in list_display should be linked to the “change” page for an object.
924926
# Example of usage: list_display_links = ("id", "mobile_number", "email")
925927
list_display_links: Sequence[str] = ()
@@ -1235,7 +1237,6 @@ <h2>InlineModelAdmin objects</h2>
12351237

12361238
@register(Author)
12371239
class AuthorAdmin(TortoiseModelAdmin):
1238-
label_fields = ("name",)
12391240
inlines = (
12401241
BookInline,
12411242
)
@@ -1355,15 +1356,24 @@ <h2>Changelog</h2>
13551356
<hr class="small-divider" />
13561357
<!-- <p class="alert alert-info mb-5"> For Future Updates Follow Us <a target="_blank" href="http://themeforest.net/user/harnishdesign?ref=HarnishDesign">@themeforest</a> / <a target="_blank" href="http://facebook.com/harnishdesign">@facebook</a> / <a target="_blank" href="http://twitter.com/harnishdesign">@twitter</a> / <a target="_blank" href="https://dribbble.com/harnishdesign">@Dribbble</a></p> -->
13571358

1359+
<h3 id="v0_1_25">
1360+
Version 0.1.25
1361+
<small class="text-muted">(25 March, 2024)</small>
1362+
</h3>
1363+
<ul class="changelog">
1364+
<li>Fixed inlines api.</li>
1365+
<li>Fixed label fields.</li>
1366+
<li>Fixed inlines frontend side.</li>
1367+
</ul>
1368+
<hr class="small-divider" />
1369+
13581370
<h3 id="v0_1_24">
13591371
Version 0.1.24
13601372
<small class="text-muted">(25 March, 2024)</small>
13611373
</h3>
13621374
<ul class="changelog">
1363-
<li>
1364-
Fixed a bug with inline fk_name field. Added pydantic as
1365-
dependency.
1366-
</li>
1375+
<li>Fixed a bug with inline fk_name field.</li>
1376+
<li>Added pydantic as dependency.</li>
13671377
</ul>
13681378
<hr class="small-divider" />
13691379

examples/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ fastapi:
44

55
.PHONY: flask
66
flask:
7-
poetry run flask --app flask.dev run --debug
7+
poetry run flask --app flask.dev run --debug --host 0.0.0.0 --port 8090
88

99
.PHONY: dev_django
1010
django:
11-
poetry run python django/dev/manage.py runserver
11+
poetry run python django/dev/manage.py runserver 0.0.0.0:8090

0 commit comments

Comments
 (0)