fastadmin 0.2.14__py3-none-any.whl → 0.2.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fastadmin/models/base.py CHANGED
@@ -621,6 +621,25 @@ class ModelAdmin(BaseModelAdmin):
621
621
  """
622
622
  raise NotImplementedError
623
623
 
624
+ async def save_model(self, id: UUID | int | None, payload: dict) -> dict | None:
625
+ """This method is used to save orm/db model object.
626
+
627
+ :params id: an id of object.
628
+ :params payload: a payload from request.
629
+ :return: A saved object or None.
630
+ """
631
+ obj = await super().save_model(id, payload)
632
+ fields = self.get_model_fields_with_widget_types(with_m2m=False, with_upload=False)
633
+ password_fields = [field.name for field in fields if field.form_widget_type == WidgetType.PasswordInput]
634
+ if obj and id is None and password_fields:
635
+ # save hashed password for create
636
+ pk_name = self.get_model_pk_name(self.model_cls)
637
+ pk = obj[pk_name]
638
+ password_values = [payload[field] for field in password_fields if field in payload]
639
+ if password_values:
640
+ await self.change_password(pk, password_values[0])
641
+ return obj
642
+
624
643
 
625
644
  class DashboardWidgetAdmin:
626
645
  title: str