@@ -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 ">
256256pip 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 ">
264264export ADMIN_USER_MODEL=User
265265export ADMIN_USER_MODEL_USERNAME_FIELD=username
266266export 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 ">
287286from fastapi import FastAPI
288287from fastadmin import fastapi_app as admin_app
289288
@@ -296,16 +295,49 @@ <h4>FastAPI Framework</h4>
296295app.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 ">
309341import bcrypt
310342from tortoise.models import Model
311343from 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.
392418ADMIN_PREFIX: str = "admin"
393419
@@ -429,8 +455,8 @@ <h2>Settings</h2>
429455
430456# This value is the time format for JS widgets.
431457ADMIN_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
478503from .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 ">
699724async 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 ">
837862async 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 ">
861886from tortoise.models import Model
862887from tortoise import fields
863888from 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 ">
949974from tortoise.models import Model
950975from tortoise import fields
951976
952977class 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 ">
964989from fastadmin import TortoiseModelAdmin, TortoiseInlineModelAdmin
965990from .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
0 commit comments