English
Open in Telegram

Post#signals

12 May 2025
O
Omadbek Qosimov's blog
#signals @receiver(pre_save, sender=Blogger) def prepare_blogger_chat(sender, instance, **kwargs): """ Blogger saqlashdan oldin signal. Agar blogger.user.user_type == 'blogger' bo'lsa, uning chatini topib, undagi barcha qatnashchilarni o'chirib, faqat bloggerning o'zini qo'shadi. """ # Yangi yaratilayotgan Blogger uchun hali id bo'lmaydi if instance.id is None: # Yangi blogger, hali chati yo'q return if instance.user and instance.user.user_type == 'blogger': try: # Blogerning chatini topamiz # Ehtimol bo'lgan hamma chatlarini olamiz blogger_chat = Chat.objects.filter(participants=instance.user).first() if blogger_chat: blogger_chat.participants.clear() blogger_chat.participants.add(instance.user) blogger_chat.save() except Exception as e: print(f"Chat qayta sozlashda xatolik yuz berdi: {e}") @receiver(post_save, sender=Blogger) def update_blogger_chat(sender, instance, created, **kwargs): """ Blogger saqlagandan keyin signal. Agar user.user_type == 'blogger' va saler.user_type == 'sales' bo'lsa, bloggerning chatini topib, unga salerni qo'shadi. """ # Faqat blogerga tegishli user va saler mavjud bo'lsa if instance.user and instance.user.user_type == 'blogger' and instance.saler and instance.saler.user_type == 'sales': try: with transaction.atomic(): blogger_chats = Chat.objects.filter(participants=instance.user) if not blogger_chats.exists(): chat = Chat.objects.create() chat.participants.add(instance.user) else: chat = blogger_chats.first() chat.participants.add(instance.saler) chat.save() except Exception as e: print(f"Bloggerning chatini yangilashda xatolik yuz berdi: {e}") elif instance.user and instance.user.user_type == 'manager' and instance.saler and instance.saler.user_type == 'sales': try: with transaction.atomic(): bloggers = Blogger.objects.filter(manager=instance.user) for blogger in bloggers: blogger.saler = instance.saler blogger.save() # Bu o'z navbatida ushbu signal uchun yangi chaqiruvlarni yaratadi except Exception as e: print(f"Bloggerning chatini yangilashda xatolik yuz berdi: {e}")
360 ·

Nearby in the feed

OOmadbek Qosimov's blogai.oqdev.uzOOmadbek Qosimov's bloghttps://github.com/ArtemiusUA/django-cml/
this message
OOmadbek Qosimov's bloghttps://www.linkedin.com/pulse/how-reduce-react-native-apk-size-universal-gopal-gupta-srnaf/OOmadbek Qosimov's bloguse local postgres in docker version: "3.8" services: python-app: build: . container_name: python_app ports: - "8081:8000" volumes: - .:/app working_dir: /app
OOmadbek Qosimov's blogOmadbek Qosimov's blog@python_Oqdev · channel · Tech
28subscribers145posts in the index
Venue feed Open in Telegram

An open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · Index limits · Remove a page · Catalog · Search · How we count