From 187c14d6b04cf2de78a528eab266143aaa16f76c Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 22 Feb 2024 12:23:46 +0300 Subject: [PATCH] slug-patch-on-create --- resolvers/editor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resolvers/editor.py b/resolvers/editor.py index b28ad78e..5538daca 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -60,7 +60,12 @@ async def create_shout(_, info, inp): 'published_at': None, 'created_at': current_time, # Set created_at as Unix timestamp } - + same_slug_shout = session.query(Shout).filter(Shout.slug == shout_dict.get('slug')).first() + c = 1 + while same_slug_shout is not None: + same_slug_shout = session.query(Shout).filter(Shout.slug == shout_dict.get('slug')).first() + c += 1 + shout_dict['slug'] += f'-{c}' new_shout = Shout(**shout_dict) session.add(new_shout) session.commit()