|
18 | 18 | from django.db.models import QuerySet |
19 | 19 | from django.utils import timezone |
20 | 20 | from django.utils.translation import gettext_lazy as _ |
| 21 | + |
| 22 | +from serializers import chat_user |
21 | 23 | from system_manage.models.chat_user_token_quota import ChatUserTokenQuota |
22 | 24 |
|
23 | | -from application.models import Application, ChatRecord, Chat, ApplicationVersion, ChatUserType, ApplicationTypeChoices, \ |
24 | | - ExecuteType |
| 25 | +from application.models import ( |
| 26 | + Application, |
| 27 | + ChatRecord, |
| 28 | + Chat, |
| 29 | + ApplicationVersion, |
| 30 | + ChatUserType, |
| 31 | + ApplicationTypeChoices, |
| 32 | + ExecuteType, |
| 33 | +) |
25 | 34 | from application.serializers.application_chat import ChatCountSerializer |
26 | 35 | from common.constants.cache_version import Cache_Version |
27 | 36 | from common.database_model_manage.database_model_manage import DatabaseModelManage |
@@ -199,7 +208,9 @@ def get_application(self): |
199 | 208 | def get_chat_user(self, asker=None): |
200 | 209 | if self.chat_user: |
201 | 210 | return self.chat_user |
202 | | - chat_user_model = DatabaseModelManage.get_model("chat_user") |
| 211 | + from system_manage.models import ChatUser |
| 212 | + |
| 213 | + chat_user_model = ChatUser |
203 | 214 | if self.chat_user_type == ChatUserType.CHAT_USER.value and chat_user_model: |
204 | 215 | chat_user = QuerySet(chat_user_model).filter(id=self.chat_user_id).first() |
205 | 216 | return { |
@@ -336,11 +347,17 @@ def set_chat(self, question): |
336 | 347 | ).save() |
337 | 348 |
|
338 | 349 | def save_chat(self): |
339 | | - Chat(id=self.chat_id, application_id=self.application_id, abstract="新建对话", |
340 | | - execute_type=ExecuteType.DEBUG if self.debug else ExecuteType.CHAT, |
341 | | - chat_user_id=self.chat_user_id, chat_user_type=self.chat_user_type, |
342 | | - ip_address=self.ip_address, source=self.source, |
343 | | - asker=self.get_chat_user()).save() |
| 350 | + Chat( |
| 351 | + id=self.chat_id, |
| 352 | + application_id=self.application_id, |
| 353 | + abstract="新建对话", |
| 354 | + execute_type=ExecuteType.DEBUG if self.debug else ExecuteType.CHAT, |
| 355 | + chat_user_id=self.chat_user_id, |
| 356 | + chat_user_type=self.chat_user_type, |
| 357 | + ip_address=self.ip_address, |
| 358 | + source=self.source, |
| 359 | + asker=self.get_chat_user(), |
| 360 | + ).save() |
344 | 361 |
|
345 | 362 | def set_chat_variable(self, chat_context): |
346 | 363 | if not self.debug: |
|
0 commit comments