Django发布的数据不会保存在admin DB中

问题描述 投票:0回答:1

我希望我的表单数据保存在数据库中,但它不起作用另外如何在计算机中保存该帖子数据?(如果这个问题不清楚,你可以忽略)

view.朋友

class task_generation_view(FormView):
    form_class = TaskGenerationForm
    model = TaskGeneration
    fields = '__all__'
    template_name = "task_generation.html"
    success_url = reverse_lazy('data_upload')

models.朋友

class TaskGeneration(models.Model):
    classification = '분류 알고리즘'
    regression = '회귀 알고리즘'
    clustering ='군집화 알고리즘'
    detection = '이상치 탐지 알고리즘'
    reinforce ='강화학습 알고리즘'
    SELECT_ALGORITHM_CHOICES = (
        (classification, '분류 알고리즘'),
        (regression,'회귀 알고리즘'),
        (clustering, '군집화 알고리즘'),
        (detection, ' 이상치 탐지 알고리즘'),
        (clustering,' 강화학습 알고리즘'),
    )
    algorithm = models.CharField(max_length=30, choices = SELECT_ALGORITHM_CHOICES, default = classification)
    readyData = models.BooleanField()

URLs.朋友

urlpatterns = [
    #url('$', ModelingView_model.as_view()),
    url('task_generation', task_generation_view.as_view()),
    url('data_upload', data_upload_view.as_view(), name='data_upload'),
    url('data_load', data_load_view.as_view()),
    url('data_exploration', data_exploration_view.as_view(), name='data_exploration'),
    url('data_variable_Identification', data_variable_identification_view.as_view()),

    # url('', FileUploadView.as_view(), name='upload'),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

forms.朋友

class TaskGenerationForm(forms.ModelForm):
    class Meta:
        model = TaskGeneration
        fields = ('algorithm', 'readyData')
        widgets ={
            'algorithm' : forms.Select(attrs = {'class' : 'btn btn-info btn-select btn-select-light'}),
        }

task_generation.html

 <form method = "post" enctype="multipart/form-data">
...
  {% csrf_token %}
  {{ form.algorithm }}
...
  {% csrf_token %}
  {{ form.readyData }}
<button type="submt">submit</button>
 </form>
python html django
1个回答
0
投票

为了将来参考,task_generation_view中基于类的视图views.py继承自错误的类。它应该扩展CreateView而不是FormView。我建议在Django文档网站here上阅读更多关于CBV的内容。

© www.soinside.com 2019 - 2024. All rights reserved.