Skip to content

Commit 8767092

Browse files
committed
Fixed #15
1 parent 96d0bb2 commit 8767092

3 files changed

Lines changed: 130 additions & 55 deletions

File tree

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,59 @@ Go to [http://localhost:8000/admin](http://localhost:8000/admin).
7878

7979
For additional information see [ModelAdmin](https://vsdudakov.github.io/fastadmin#model_admin_objects) and [InlineModelAdmin](https://vsdudakov.github.io/fastadmin#inline_model_admin_objects) documentation.
8080

81-
##### For Django and Flask:
81+
##### For Flask:
82+
83+
```python
84+
from flask import Flask
85+
from fastadmin import flask_app as admin_app
86+
87+
...
88+
89+
app = Flask(__name__)
90+
91+
...
92+
93+
app.register_blueprint(admin_app, url_prefix="/admin")
94+
95+
...
96+
```
97+
98+
Run your project (see [https://flask.palletsprojects.com/en/2.2.x/quickstart/](https://flask.palletsprojects.com/en/2.2.x/quickstart/)):
99+
100+
```bash
101+
flask ...
102+
```
103+
104+
Go to [http://localhost:5000/admin](http://localhost:5000/admin).
105+
106+
For additional information see [ModelAdmin](https://vsdudakov.github.io/fastadmin#model_admin_objects) and [InlineModelAdmin](https://vsdudakov.github.io/fastadmin#inline_model_admin_objects) documentation.
107+
108+
109+
##### For Django:
110+
111+
In root urls.py
112+
113+
```python
114+
from django.urls import path
115+
from fastadmin import get_admin_urls
116+
117+
...
118+
119+
urlpatterns = [
120+
path("admin/", get_admin_urls()),
121+
]
122+
```
123+
124+
Run your project (see [https://docs.djangoproject.com/en/4.1/intro/](https://docs.djangoproject.com/en/4.1/intro/):
125+
126+
```bash
127+
python manage.py runserver
128+
```
129+
130+
Go to [http://localhost:8000/admin](http://localhost:8000/admin).
131+
132+
For additional information see [ModelAdmin](https://vsdudakov.github.io/fastadmin#model_admin_objects) and [InlineModelAdmin](https://vsdudakov.github.io/fastadmin#inline_model_admin_objects) documentation.
82133

83-
Coming soon...
84134

85135
#### Register ORM models
86136

docs/index.html

Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,20 @@ <h3>Installation</h3>
252252
<p class="lead">Follow the steps below to setup FastAdmin</p>
253253
<p class="lead">Install the package using pip:</p>
254254
<pre>
255-
<code class="language-bash">
255+
<code class="language-bash">
256256
pip install fastadmin
257-
</code>
258-
</pre>
257+
</code>
258+
</pre>
259259
<p class="lead">
260260
Configure FastAdmin with virtual environment variables:
261261
</p>
262262
<pre>
263-
<code class="language-bash">
263+
<code class="language-bash">
264264
export ADMIN_USER_MODEL=User
265265
export ADMIN_USER_MODEL_USERNAME_FIELD=username
266266
export ADMIN_SECRET_KEY=secret_key
267-
</code>
268-
</pre>
267+
</code>
268+
</pre>
269269
<p class="alert alert-warning">
270270
Note: You can add these variables to .env and use python-dotenv
271271
to load them.
@@ -281,9 +281,8 @@ <h3>Quick Tutorial</h3>
281281
use in 3 steps.
282282
</p>
283283
<h4>FastAPI Framework</h4>
284-
<p class="lead">Mount FastAdmin App</p>
285284
<pre>
286-
<code class="language-python">
285+
<code class="language-python">
287286
from fastapi import FastAPI
288287
from fastadmin import fastapi_app as admin_app
289288

@@ -296,16 +295,49 @@ <h4>FastAPI Framework</h4>
296295
app.mount("/admin", admin_app)
297296

298297
...
299-
</code>
300-
</pre>
298+
</code>
299+
</pre>
300+
<h4>Flask Framework</h4>
301+
<pre>
302+
<code class="language-python">
303+
from flask import Flask
304+
from fastadmin import flask_app as admin_app
305+
306+
...
307+
308+
app = Flask(__name__)
309+
310+
...
311+
312+
app.register_blueprint(admin_app, url_prefix="/admin")
313+
314+
...
315+
</code>
316+
</pre>
317+
<h4>Django Framework</h4>
318+
<p class="lead">
319+
In root urls.py:
320+
</p>
321+
<pre>
322+
<code class="language-python">
323+
from django.urls import path
324+
from fastadmin import get_admin_urls
325+
326+
...
327+
328+
urlpatterns = [
329+
path("admin/", get_admin_urls()),
330+
]
331+
</code>
332+
</pre>
301333
<p class="alert alert-warning">
302334
Note: Use prefix "/admin". You can configure the prefix later.
303335
See <a href="#settings">section</a>.
304336
</p>
305337
<p class="lead">Create and register first AdminModel classes</p>
306338
<h5>Tortoise ORM</h5>
307339
<pre>
308-
<code class="language-python">
340+
<code class="language-python">
309341
import bcrypt
310342
from tortoise.models import Model
311343
from fastadmin import register, TortoiseModelAdmin
@@ -350,8 +382,8 @@ <h5>Tortoise ORM</h5>
350382
list_display_links = ("id",)
351383
list_filter = ("id", "name")
352384
search_fields = ("name",)
353-
</code>
354-
</pre>
385+
</code>
386+
</pre>
355387
<p class="alert alert-warning">
356388
Note: You have to implement authenticate method for FastAdmin
357389
authentication on AdminModel class which is registered for
@@ -368,12 +400,6 @@ <h5>SQLAlchemy ORM</h5>
368400
<p class="alert alert-info">Coming soon...</p>
369401
<h5>Pony ORM</h5>
370402
<p class="alert alert-info">Coming soon...</p>
371-
<h4>Django Framework</h4>
372-
<p class="alert alert-info">Coming soon...</p>
373-
<h5>Django ORM</h5>
374-
<p class="alert alert-info">Coming soon...</p>
375-
<h4>Flask Framework</h4>
376-
<p class="alert alert-info">Coming soon...</p>
377403
</section>
378404
<hr class="divider" />
379405

@@ -387,7 +413,7 @@ <h2>Settings</h2>
387413
<p class="lead">There are settings with default values:</p>
388414

389415
<pre>
390-
<code class="language-python">
416+
<code class="language-python">
391417
# This value is the prefix you used for mounting FastAdmin app for FastAPI.
392418
ADMIN_PREFIX: str = "admin"
393419

@@ -429,8 +455,8 @@ <h2>Settings</h2>
429455

430456
# This value is the time format for JS widgets.
431457
ADMIN_TIME_FORMAT: str = "HH:mm:ss"
432-
</code>
433-
</pre>
458+
</code>
459+
</pre>
434460
<p class="alert alert-warning">
435461
Note: Settings without default values are required.
436462
</p>
@@ -445,10 +471,10 @@ <h3>Tortoise ORM</h3>
445471
and register admin models and inlines.
446472
</p>
447473
<pre>
448-
<code class="language-python">
449-
from fastadmin.tortoise import TortoiseModelAdmin, TortoiseInlineModelAdmin
450-
</code>
451-
</pre>
474+
<code class="language-python">
475+
from fastadmin import TortoiseModelAdmin, TortoiseInlineModelAdmin
476+
</code>
477+
</pre>
452478
<h3>SQLAlchemy ORM</h3>
453479
<p class="alert alert-info">Coming soon...</p>
454480
<h3>Pony ORM</h3>
@@ -473,8 +499,7 @@ <h3>The register decorator</h3>
473499
</p>
474500
<pre>
475501
<code class="language-python">
476-
from fastadmin import register
477-
from fastadmin.tortoise import TortoiseModelAdmin
502+
from fastadmin import register, TortoiseModelAdmin
478503
from .models import Author
479504

480505
@register(Author)
@@ -512,7 +537,7 @@ <h3>The register decorator</h3>
512537
<h3>ModelAdmin options</h3>
513538
<p class="lead">Base options:</p>
514539
<pre>
515-
<code class="language-python">
540+
<code class="language-python">
516541
# A list of actions to make available on the change list page.
517542
# You have to implement methods with names like action_name in your ModelAdmin class and decorate them with @action decorator.
518543
# Example of usage:
@@ -642,11 +667,11 @@ <h3>ModelAdmin options</h3>
642667
# An empty collection disables sorting for all columns.
643668
# Example of usage: sortable_by = ("mobile_number", "email")
644669
sortable_by: Sequence[str] = ()
645-
</code>
646-
</pre>
670+
</code>
671+
</pre>
647672
<p class="lead">Specific options:</p>
648673
<pre>
649-
<code class="language-python">
674+
<code class="language-python">
650675
# Labels for model. We use them in select, autocomplete and other wigets where we represent model items.
651676
# We user first from label_fields, if it is empty, we use the second and so on.
652677
# If you don't set this attribute, we will use id attr as label.
@@ -685,8 +710,8 @@ <h3>ModelAdmin options</h3>
685710
# See InlineModelAdmin section for more details.
686711
inlines: Sequence[type[InlineModelAdmin]] = ()
687712

688-
</code>
689-
</pre>
713+
</code>
714+
</pre>
690715
</section>
691716
<hr class="small-divider" />
692717

@@ -695,7 +720,7 @@ <h3>ModelAdmin methods</h3>
695720
<p class="lead">Base methods:</p>
696721

697722
<pre>
698-
<code class="language-python">
723+
<code class="language-python">
699724
async def get_list(
700725
self,
701726
offset: int | None = None,
@@ -829,11 +854,11 @@ <h3>ModelAdmin methods</h3>
829854
"""
830855
...
831856

832-
</code>
833-
</pre>
857+
</code>
858+
</pre>
834859
<p class="lead">Specific methods:</p>
835860
<pre>
836-
<code class="language-python">
861+
<code class="language-python">
837862
async def authenticate(self, username: str, password: str) -> UUID | int | None:
838863
"""This method is used to implement authentication for settings.ADMIN_USER_MODEL orm/db model.
839864

@@ -842,8 +867,8 @@ <h3>ModelAdmin methods</h3>
842867
:return: An user id or None.
843868
"""
844869
...
845-
</code>
846-
</pre>
870+
</code>
871+
</pre>
847872
</section>
848873
<hr class="divider" />
849874

@@ -857,7 +882,7 @@ <h2>InlineModelAdmin objects</h2>
857882
Tortoise Example:
858883
</p>
859884
<pre>
860-
<code class="language-python">
885+
<code class="language-python">
861886
from tortoise.models import Model
862887
from tortoise import fields
863888
from fastadmin import register, TortoiseModelAdmin, TortoiseInlineModelAdmin
@@ -882,8 +907,8 @@ <h2>InlineModelAdmin objects</h2>
882907
inlines = (
883908
BookInline,
884909
)
885-
</code>
886-
</pre>
910+
</code>
911+
</pre>
887912
</section>
888913
<hr class="small-divider" />
889914

@@ -896,7 +921,7 @@ <h3>InlineModelAdmin options</h3>
896921
</p>
897922
<p class="lead">Specific options:</p>
898923
<pre>
899-
<code class="language-python">
924+
<code class="language-python">
900925
# The model class which the inline is using. This is required.
901926
model: Any
902927

@@ -918,8 +943,8 @@ <h3>InlineModelAdmin options</h3>
918943

919944
# An override to the verbose_name_plural from the model's inner Meta class.
920945
verbose_name_plural: str | None = None
921-
</code>
922-
</pre>
946+
</code>
947+
</pre>
923948
</section>
924949
<hr class="small-divider" />
925950

@@ -945,22 +970,22 @@ <h3>ForeignKey fields</h3>
945970
</p>
946971

947972
<pre>
948-
<code class="language-python">
973+
<code class="language-python">
949974
from tortoise.models import Model
950975
from tortoise import fields
951976

952977
class Friendship(Model):
953978
to_person = fields.ForeignKey("models.Person", related_name="friends")
954979
from_person = fields.ForeignKey("models.Person", related_name="from_friends")
955-
</code>
956-
</pre>
980+
</code>
981+
</pre>
957982
<p class="lead">
958983
If you wanted to display an inline on the Person admin
959984
add/change pages you need to explicitly define the foreign key
960985
since it is unable to do so automatically:
961986
</p>
962987
<pre>
963-
<code class="language-python">
988+
<code class="language-python">
964989
from fastadmin import TortoiseModelAdmin, TortoiseInlineModelAdmin
965990
from .models import Friendship
966991

@@ -972,8 +997,8 @@ <h3>ForeignKey fields</h3>
972997
inlines = (
973998
FriendshipInline,
974999
)
975-
</code>
976-
</pre>
1000+
</code>
1001+
</pre>
9771002
</section>
9781003
<hr class="small-divider" />
9791004

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastadmin"
3-
version = "0.1.18"
3+
version = "0.1.19"
44
description = ""
55
authors = ["Seva D <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)