当我更新记录时,会在Djang中抛出一个结束行

2024-03-29 07:16:06 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试使用窗体更新Django中的记录时,出现了一个错误。我得到一个错误,记录正在更新,但删除了结束行。如何解决这个问题

在Postgresql中更新之前:

enter image description here

在Postgresql中更新后:

enter image description here

我不想更改行顺序,但记录更新时更改行顺序

视图代码:

from django.shortcuts import render,redirect,get_object_or_404
from Table_definition.forms import TableDefinitionsForms
from Table_definition.models import sysTables

def update_table(request,id):
    process_type = "update"
    table_data = get_object_or_404(sysTables, id = id)
    table_form = TableDefinitionsForms(
        request.POST or None,
        request.FILES or None,
        instance=table_data)

    if table_form.is_valid():
        table_form.save()
        return redirect("Table_definition:table") 

    context = {
        "table_form":table_form,
        "process_type":process_type
    }
    return render(request, 'tableCreate.html', context)

表格代码:

from django import forms
from Table_definition.models import sysTables

class TableDefinitionsForms(forms.ModelForm):
    class Meta:
        model = sysTables
        fields = [
            'name',
            'alias' , 
            'aliasLng1' ,
            'aliasLng2' ,
            'chistory',
            'rhistory',
            'uhistory' ,
            'dhistory' ,
            'log',
        ]
        widgets = {
            'name':forms.TextInput(attrs={'placeholder': '','class':'rc-form-control-input form-control-user'}),
            'alias': forms.TextInput(attrs={'placeholder': '','class':'rc-form-control-input form-control-user'}),
            'aliasLng1': forms.TextInput(attrs={'placeholder': '','class':'rc-form-control-input form-control-user'}),
            'aliasLng2': forms.TextInput(attrs={'placeholder': '','class':'rc-form-control-input form-control-user'}),
            'chistory': forms.CheckboxInput(attrs={'placeholder': '','class':'form-check-input','id':'chistory'}),
            'rhistory': forms.CheckboxInput(attrs={'placeholder': '','class':'form-check-input','id':'rhistory'}),
            'uhistory': forms.CheckboxInput(attrs={'placeholder': '','class':'form-check-input','id':'uhistory'}),
            'dhistory': forms.CheckboxInput(attrs={'placeholder': '','class':'form-check-input','id':'dhistory'}),
            'log': forms.CheckboxInput(attrs={'placeholder': '','class':'form-check-input','id':'log'}),
        }

Tags: orfromimportformidinputchecktable