我在Django中有一个名为“ Project”的应用程序。 基本任务是我应该能够创建,搜索和修改项目。 创建页面工作正常。在搜索页面上,我从数据库中给出了现有创建项目的下拉列表。现在,如果我从下拉列表中选择一个值,它应该以可编辑的格式为我提供与该搜索列关联的整行,以便我可以对其进行修改。
我有三个文件: models.py views.py 和用于显示表单的.html文件
models.py:
class Project(models.Model):
JIRAID = models.CharField(max_length=20,null=True)
projectID = models.AutoField(primary_key=True)
projectName = models.CharField(max_length=100)
projectDescription = models.CharField(max_length=100)
projectStartDate = models.DateField()
projectEndDate = models.DateField()
projectEstimatedLOE = models.IntegerField()
createdBy = models.CharField(max_length=30)
createdAt = models.DateTimeField(default=datetime.datetime.now,null=True,blank=True)
updatedAt = models.DateTimeField(default=datetime.datetime.now,null=True,blank=True)
View.py:
def projectcreation(request):
context = {'form': Project}
if request.method=='POST':
form = ProjectCreationForm(request.POST)
if form.is_valid():
JIRAID=request.POST.get('JIRAID')
projectID=request.POST.get('projectID')
projectName=request.POST.get('projectName')
projectDescription=request.POST.get('projectDescription')
projectStartDate=request.POST.get('projectStartDate')
projectEndDate=request.POST.get('projectEndDate')
projectEstimatedLOE=request.POST.get('projectEstimatedLOE')
createdBy=User.objects.get(username=request.user.username)
form.save()
return render(request,'projectpages/projectcreateconfirmation.html')
else:
return render(request,'projectpages/projectcreate.html')
else:
return render(request,'projectpages/projectcreate.html',context)
def projectsearch(request):
projectid_list = Project.objects.filter(createdBy=request.user.username)
return render(request,'projectpages/projectsearch.html',{'projectcreation':projectid_list})
def projectmodification(request):
projectid_list = Project.objects.filter(createdBy=request.user.username)
return render(request, 'projectpages/projectmodification.html', {'projectcreation': projectid_list})
如果我从搜索页面的下拉列表中选择一个值,则应该在修改页面上以可编辑的格式获取与该值关联的整行。