mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-17 04:40:13 +08:00
Save duplicated method call into variable
This commit is contained in:
@ -86,13 +86,14 @@ async def update(
|
|||||||
):
|
):
|
||||||
form = await request.form()
|
form = await request.form()
|
||||||
data, m2m_data = await model_resource.resolve_data(request, form)
|
data, m2m_data = await model_resource.resolve_data(request, form)
|
||||||
|
m2m_fields = model_resource.get_m2m_field()
|
||||||
async with in_transaction() as conn:
|
async with in_transaction() as conn:
|
||||||
obj = (
|
obj = (
|
||||||
await model.filter(pk=pk)
|
await model.filter(pk=pk)
|
||||||
.using_db(conn)
|
.using_db(conn)
|
||||||
.select_for_update()
|
.select_for_update()
|
||||||
.get()
|
.get()
|
||||||
.prefetch_related(*model_resource.get_m2m_field())
|
.prefetch_related(*m2m_fields)
|
||||||
)
|
)
|
||||||
await obj.update_from_dict(data).save(using_db=conn)
|
await obj.update_from_dict(data).save(using_db=conn)
|
||||||
for k, items in m2m_data.items():
|
for k, items in m2m_data.items():
|
||||||
@ -105,7 +106,7 @@ async def update(
|
|||||||
.using_db(conn)
|
.using_db(conn)
|
||||||
.select_related(*model_resource.get_fk_field())
|
.select_related(*model_resource.get_fk_field())
|
||||||
.get()
|
.get()
|
||||||
.prefetch_related(*model_resource.get_m2m_field())
|
.prefetch_related(*m2m_fields)
|
||||||
)
|
)
|
||||||
inputs = await model_resource.get_inputs(request, obj)
|
inputs = await model_resource.get_inputs(request, obj)
|
||||||
if "save" in form.keys():
|
if "save" in form.keys():
|
||||||
|
Reference in New Issue
Block a user