[英]How to send firebase notifications using django-admin panel or Admin account?
I'm developing an android app in client side and django admin panel in server side. 我在客户端开发android应用程序,在服务器端开发django管理面板。 What I need to do is sending firebase notifications to single or all users, I have already registered android app to firebase .
我需要做的是向单个或所有用户发送Firebase通知,我已经将Android应用程序注册到firebase。
I know I should use django-fcm . 我知道我应该使用django-fcm。
I need a recommendation or any suggestion to make it right. 我需要一个建议或任何建议以使其正确。
Can I have a page to send notifications to users that only admin account can access to it? 我可以有一个页面发送通知给只有管理员帐户可以访问的用户吗?
Any suggestions will be helpful. 任何建议都会有所帮助。
I searched a lot, but not found anything. 我搜索了很多,但没有找到任何东西。
You can use fcm_django for your requirement 您可以根据需要使用fcm_django
Notification to send for all users 发送给所有用户的通知
from fcm_django.models import FCMDevice
device = FCMDevice.objects.all()
device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})
Notification to send for single user 通知发送给单个用户
from fcm_django.models import FCMDevice
device = FCMDevice.objects.get(user=user_id)
device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})
In admin.py 在admin.py中
class YourModel(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
try:
user_instance = User.objects.get(id=obj.user.id)
# above fcm code
except Exception as e:
print(e.args)
pass
super(YourModel, self).save_model(request, obj, form, change)
admin.site.register(YourModel,YourModelAdmin)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.