Search code examples
pythondjangodjango-rest-frameworkdjango-notification

Notification in django rest API


I want to make a notification system in django so that, when you add a new entry to the database I get notified. As admin I do everything in the Django Rest API


Solution

  • def create_profile(sender, instance, created, **kwargs):
        if created:
            instance.rooms.room_bool = instance.room_bool
            instance.rooms.save()
            token = '5419477:AAHuyagslasglfsE9O-90vgiDHVTiV2KmqFRNw'
            URL = 'https://api.telegram.org/bot' + token + '/sendMessage'
            for chat_id in ADMINS:
                try:
                    data = {'chat_id': chat_id, 'text': "Забронирован один номер через Ресепшен\n\n"
                                                        "Посмотрите по ссылке http://127.0.0.1:8000/admin/reg_admin/registration/\n\n"
                                                        "Нажмите /start чтобы вывести меню администратора"}
                    requests.post(URL, data=data)
                except Exception:
                    pass
    

    using signals.py, I sent a message to the bot via json