From my research online there are many questions related to what i am about to ask. Solutions i saw do not solve my problem because mine is related with django channels and signals .
Here is a post save signal code in my consumer(channels).
private chat consummer
class ChatConsummer(AsyncConsumer):
async def websocket_connect(self,event):
await self.channel_layer.group_add(
"private_chat",
self.channel_name,
)
data={
'chats':data_array
}
def Create_Notify(sender,instance,**kwargs):
data={'notificat':'notication'}
notification_data={
'notify':data,
}
async_to_sync(get_channel_layer().group_send)("private_chat", {"type": "Send_Message",'text':json.dumps(notification_data)})
post_save.connect(Create_Notify,sender=notifyall)
def credit_gotten(instance):
receiver_credit=0.0
return receiver_credit
#create a notification object when ever a rating model is saved
def save_rating(sender,instance,**kwargs):
obj_notification=notifyall.objects.create()
post_save.connect(save_rating,sender=RatingModel)
So in my code, i am accessing the channel layer outside the consumer function meaning i can not use self.scope['user'] to get the current login user .
I am using post_save signal function making it impossible to use request to access the current login in user . So please help me, i need to access the current login user in my post_save signal which calls channel layer out outside a channel consumer function .