我是 Web 编程的新手,我正在尝试创建一种可以聚合许多 IP 地址和端口的表单,当我单击只有一个 IP 和端口的峰会时它可以工作并且我的模型已更新,但是当我尝试添加多个它不起作用。我意识到索引没有更新,但我不知道如何修复它
在此处输入图像描述:
#观点
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.forms import modelformset_factory
from BrainCH.forms import formulario_crear_serv,formulario_members
from django.contrib import messages
from django.db import transaction,IntegrityError
from F5APP.models import CrearServicio,members
def Home(request):
diccionario_home = {}
return render(request,"home.html",diccionario_home)
#return HttpResponse("Home")
def NuevoServicio(request):
diccionario_crearservicio={}
Membersformset=modelformset_factory(members, form=formulario_members)
form =formulario_crear_serv(request.POST or None)
formset=Membersformset(request.POST or None, queryset=members.objects.none(), prefix="members")
if request.method== "POST":
if form.is_valid() and formset.is_valid():
try:
with transaction.atomic():
crearServicio = form.save(commit=False)
crearServicio.save()
for member in formset:
data=member.save(commit=False)
data.crearServicio = crearServicio
data.save()
#print("paso 7")
except IntegrityError:
print("Error")
return redirect("list")
diccionario_crearservicio["formset"] = formset
diccionario_crearservicio["form"] = form
return render(request,"CrearServicio.html",diccionario_crearservicio)
def list(request):
datas= CrearServicio.objects.all()
return render(request,"list.html",{"datas":datas})
慕妹3146593
相关分类