some first models of pos & add required to attributes

This commit is contained in:
2025-07-21 09:39:31 +03:30
parent c87204c134
commit ebc79a7dbd
14 changed files with 446 additions and 17 deletions

View File

@@ -24,7 +24,42 @@ class MyConsumer(AsyncWebsocketConsumer):
unit = await get_unit(int(message))
print("Received:", message)
# پاسخ به کلاینت
await self.send(text_data=json.dumps({
"message": unit
"message": unit.unit
}))
class SendFromServerConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.group_name = 'mojtaba_group' # noqa
await self.channel_layer.group_add(
self.group_name,
self.channel_name
)
await self.accept()
await self.send(text_data=json.dumps({"message": "Connected!"}))
async def disconnect(self, code):
await self.channel_layer.group_discard(
self.group_name,
self.channel_name
)
async def receive(self, text_data=None, bytes_data=None):
data = json.loads(text_data)
msg = data.get("message", "")
await self.channel_layer.group_send(
self.group_name,
{
"type": "chat.message",
"message": msg
}
)
async def chat_message(self, event):
message = event['message']
await self.send(text_data=json.dumps({
"message": message
}))

View File

@@ -2,5 +2,5 @@ from django.urls import re_path
from apps.authentication.websocket import consumer
websocket_urlpatterns = [
re_path(r"ws/somepath/$", consumer.MyConsumer.as_asgi()),
re_path(r"ws/somepath/$", consumer.SendFromServerConsumer.as_asgi()),
]