consumers
@database_sync_to_async
def create_new_message(self, text):
new_message = Message.objects.create(
author=self.scope['user'],
text=text,
object_id=int(self.room_name),
created_at=timezone.now(),
url=f'{self.scope["user"].id}%{int(self.room_name)}'
)
author = self.scope['user']
object_id = int(self.room_name)
if FirstMessages.objects.filter(author=author, object_id=object_id):
user = FirstMessages.objects.get(author=author, object_id=object_id)
user.author = self.scope['user'],
user.text = text,
user.object_id = int(self.room_name),
user.created_at = timezone.now(),
user.url = f'{self.scope["user"].id}%{int(self.room_name)}',
user.save()
else:
FirstMessages.objects.update_or_create(author=self.scope['user'],
text=text,
object_id=int(self.room_name),
created_at=timezone.now(),
url=f'{self.scope["user"].id}%{int(self.room_name)}'
)
return new_message
ошибка:
ValueError: Cannot assign "(<channels.auth.User Lazy Object object at 0x0000025FC4039310>,)": "First Messages.author" must be a "User" instance.