From b616c4eedafbfed725e4dec5e846e1f52126c7de Mon Sep 17 00:00:00 2001 From: vsdudakov Date: Wed, 21 Aug 2024 18:06:43 +0300 Subject: [PATCH] Fix --- docs/index.html | 2 +- fastadmin/models/orms/ponyorm.py | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/index.html b/docs/index.html index f4b9eef..1844e22 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,7 +2,7 @@
  • - -->

    FastAdmin | Documentation

    • Created: 7 March 2023
    • Updated: 14 August 2024

    Introduction

    FastAdmin is an easy-to-use Admin Dashboard App for FastAPI/Django/Flask inspired by Django Admin.

    FastAdmin was built with relations in mind and admiration for the excellent and popular Django Admin. It's engraved in its design that you may configure your admin dashboard for FastAPI/Django/Flask easiest way.

    FastAdmin is designed to be minimalistic, functional and yet familiar.


    Getting Started

    If you have any questions that are beyond the scope of the documentation, Please feel free to email us.

    Installation

    Follow the steps below to setup FastAdmin:

    Install the package using pip:

    Note: For zsh and macos use: pip install fastadmin[fastapi,django]

    +              -->  

    FastAdmin | Documentation

    • Created: 7 March 2023
    • Updated: 21 August 2024

    Introduction

    FastAdmin is an easy-to-use Admin Dashboard App for FastAPI/Django/Flask inspired by Django Admin.

    FastAdmin was built with relations in mind and admiration for the excellent and popular Django Admin. It's engraved in its design that you may configure your admin dashboard for FastAPI/Django/Flask easiest way.

    FastAdmin is designed to be minimalistic, functional and yet familiar.


    Getting Started

    If you have any questions that are beyond the scope of the documentation, Please feel free to email us.

    Installation

    Follow the steps below to setup FastAdmin:

    Install the package using pip:

    Note: For zsh and macos use: pip install fastadmin[fastapi,django]

       
     
     pip install fastadmin[fastapi,django]  # for fastapi with django orm
    diff --git a/fastadmin/models/orms/ponyorm.py b/fastadmin/models/orms/ponyorm.py
    index 37b5d0e..a6ad59f 100644
    --- a/fastadmin/models/orms/ponyorm.py
    +++ b/fastadmin/models/orms/ponyorm.py
    @@ -328,10 +328,12 @@ def orm_delete_obj(self, id: UUID | int) -> None:
             :params id: an id of object.
             :return: None.
             """
    -        # TODO: fix me
    -        # delete(o for o in self.model_cls if getattr(o, self.get_model_pk_name(self.model_cls)) == id)
    -        # flush()
    -        # commit()
    +        obj = next((i for i in self.model_cls.select(**{self.get_model_pk_name(self.model_cls): id})), None)
    +        if not obj:
    +            return
    +        obj.delete()
    +        flush()
    +        commit()
     
         @sync_to_async
         @db_session
    @@ -366,14 +368,12 @@ def orm_save_m2m_ids(self, obj: Any, field: str, ids: list[int | UUID]) -> None:
             obj = next((i for i in self.model_cls.select(**{key_id: getattr(obj, key_id)})), None)
             if not obj:
                 return
    -        # TODO: fix me
    -        # if ids:
    -        #     rel_model_cls = getattr(self.model_cls, field).py_type
    -        #     rel_key_id = self.get_model_pk_name(rel_model_cls)
    -        #     rel_objs = list(rel_model_cls.select(lambda o: getattr(o, rel_key_id) in ids))
    -        #     getattr(obj, field).clear()
    -        #     for rel_obj in rel_objs:
    -        #         getattr(obj, field).add(rel_obj)
    +        getattr(obj, field).clear()
    +        if ids:
    +            rel_model_cls = getattr(self.model_cls, field).py_type
    +            rel_key_id = self.get_model_pk_name(rel_model_cls)
    +            rel_objs = list(rel_model_cls.select(lambda o: getattr(o, rel_key_id) in ids))
    +            getattr(obj, field).add(rel_objs)
             flush()
             commit()