slug-patch-on-create
All checks were successful
Deploy to core / deploy (push) Successful in 1m29s

This commit is contained in:
Untone 2024-02-22 12:23:46 +03:00
parent 8d06f59702
commit 187c14d6b0

View File

@ -60,7 +60,12 @@ async def create_shout(_, info, inp):
'published_at': None, 'published_at': None,
'created_at': current_time, # Set created_at as Unix timestamp '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) new_shout = Shout(**shout_dict)
session.add(new_shout) session.add(new_shout)
session.commit() session.commit()