Код: Выделить всё
class SemanticAiForm(forms.Form):
semantic_folder = configurate.AI_DATA_FOLDER
semantic_files = 'ai_openai_fresh_news.txt'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
semantic = self.get_semantic()
if semantic is None:
self.add_error(NON_FIELD_ERRORS, 'No data')
else:
self.fields['order'] = forms.CharField(widget=forms.Textarea())
self.fields['order'].initial = semantic.system_content
def get_semantic(self) -> Union[SemanticTxt, None]:
"""
Получает объект SemanticTxt с прочитанным файлом параметрической
конфигурации.
"""
try:
filepath = os.path.join(self.semantic_folder, self.semantic_files)
semantic = read_semantic(filepath)
except exception.SemanticError:
return
return semantic
Код: Выделить всё
'SemanticAiForm' object has no attribute 'cleaned_data'
ОБНОВЛЕНИЕ
Код: Выделить всё
class RustpdAdminSite(admin.AdminSite):
"""
Переопределение админ-части создаёт пространство для творчества.
"""
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('semantic-ai/',
self.admin_view(views_admin.SemanticAiGPT.as_view(
admin_context=self.each_context)
),
name='semantic'),
]
return custom_urls + urls
Подробнее здесь: https://stackoverflow.com/questions/789 ... jango-form