Skip to content

Commit 1cc4efd

Browse files
committed
Fixed bugs, added doc strings and tests for frontend
1 parent c6c27d5 commit 1cc4efd

2 files changed

Lines changed: 57 additions & 31 deletions

File tree

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,34 @@ If you have smth else (your own implementation of ORM and so on) you will may ov
166166

167167
```
168168
from typing import Any
169-
from io import BytesIO, StringIO
170-
from fastadmin import ModelAdmin, register, WidgetType, ExportFormat
169+
from collections import OrderedDict
170+
from fastadmin import ModelAdmin
171171
172172
class MyModelAdmin(ModelAdmin):
173173
async def save_model(self, obj: Any, payload: dict, add: bool = False) -> None:
174+
"""This method is used to save orm/db model object.
175+
176+
:params obj: an orm/db model object.
177+
:params payload: a payload from request.
178+
:params add: a flag for add or update object.
179+
:return: None.
180+
"""
174181
raise NotImplementedError
175182
176183
async def delete_model(self, obj: Any) -> None:
184+
"""This method is used to delete orm/db model object.
185+
186+
:params obj: an orm/db model object.
187+
:return: None.
188+
"""
177189
raise NotImplementedError
178190
179191
async def get_obj(self, id: str) -> Any | None:
192+
"""This method is used to get orm/db model object by id.
193+
194+
:params id: an id of object.
195+
:return: An object or None.
196+
"""
180197
raise NotImplementedError
181198
182199
async def get_list(
@@ -187,23 +204,32 @@ class MyModelAdmin(ModelAdmin):
187204
sort_by: str | None = None,
188205
filters: dict | None = None,
189206
) -> tuple[list[Any], int]:
207+
"""This method is used to get list of orm/db model objects.
208+
209+
:params offset: an offset for pagination.
210+
:params limit: a limit for pagination.
211+
:params search: a search query.
212+
:params sort_by: a sort by field name.
213+
:params filters: a dict of filters.
214+
:return: A tuple of list of objects and total count.
215+
"""
190216
raise NotImplementedError
191217
192-
async def get_export(
193-
self,
194-
format: ExportFormat | None,
195-
offset: int | None = None,
196-
limit: int | None = None,
197-
search: str | None = None,
198-
sort_by: str | None = None,
199-
filters: dict | None = None,
200-
) -> StringIO | BytesIO | None:
201-
raise NotImplementedError
218+
def get_model_fields(self) -> OrderedDict[str, dict]:
219+
"""This method is used to get all orm/db model fields
220+
with saving ordering (non relations, fk, o2o, m2m).
202221
203-
def get_model_fields(self) -> list[str]:
222+
:return: An OrderedDict of model fields.
223+
"""
204224
raise NotImplementedError
205225
206-
def get_form_widget(self, field: str) -> tuple[WidgetType, dict]:
226+
def get_form_widget(self, field_name: str) -> tuple[WidgetType, dict]:
227+
"""This method is used to get form item widget
228+
for field from orm/db model.
229+
230+
:params field_name: a model field name.
231+
:return: A tuple of widget type and widget props.
232+
"""
207233
raise NotImplementedError
208234
209235
```

fastadmin/models/base.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@ async def get_list(
212212
"""
213213
raise NotImplementedError
214214

215+
def get_model_fields(self) -> OrderedDict[str, dict]:
216+
"""This method is used to get all orm/db model fields
217+
with saving ordering (non relations, fk, o2o, m2m).
218+
219+
:return: An OrderedDict of model fields.
220+
"""
221+
raise NotImplementedError
222+
223+
def get_form_widget(self, field_name: str) -> tuple[WidgetType, dict]:
224+
"""This method is used to get form item widget
225+
for field from orm/db model.
226+
227+
:params field_name: a model field name.
228+
:return: A tuple of widget type and widget props.
229+
"""
230+
raise NotImplementedError
231+
215232
async def get_export(
216233
self,
217234
export_format: ExportFormat | None,
@@ -245,23 +262,6 @@ async def get_export(
245262
return output
246263
return None
247264

248-
def get_model_fields(self) -> OrderedDict[str, dict]:
249-
"""This method is used to get all orm/db model fields
250-
with saving ordering (non relations, fk, o2o, m2m).
251-
252-
:return: An OrderedDict of model fields.
253-
"""
254-
raise NotImplementedError
255-
256-
def get_form_widget(self, field_name: str) -> tuple[WidgetType, dict]:
257-
"""This method is used to get form item widget
258-
for field from orm/db model.
259-
260-
:params field_name: a model field name.
261-
:return: A tuple of widget type and widget props.
262-
"""
263-
raise NotImplementedError
264-
265265
def get_filter_widget(self, field_name: str) -> tuple[WidgetType, dict]:
266266
"""This method is used to get filter widget for tabel columns
267267
for field from orm/db model from list_filter parameter.

0 commit comments

Comments
 (0)