gpt4 book ai didi

python - 我如何将获取值传递给views.py中的特定模型字段

转载 作者:行者123 更新时间:2023-12-01 07:19:45 25 4
gpt4 key购买 nike

如何将 request.GET.get 值传递到 django 中的另一个表单。

views.py

def bacadmininvitoBid_views(request):
project_list = ProjectNameInviToBid.objects.all()
query = request.GET.get('query')
if query:
project_list = project_list.filter(ProjectName__icontains=query)
if request.method == 'POST':
form = invitoBidForm(request.POST, request.FILES)
if form.is_valid():
form.ProjectName = project_list
form.save()
messages.success(request, 'File has been Uploaded')
else:
form = invitoBidForm()

args = {
'form': form,
'project_list': project_list

}
return render(request, 'content/invitoBid/bacadmininvitoBid.html', args)

型号

class InviToBid(models.Model):
today = date.today()
ProjectName = models.ForeignKey('ProjectNameInviToBid', on_delete=models.CASCADE, null=True)
NameOfFile = models.CharField(max_length=255, verbose_name='Name of File')
Contract_No = models.IntegerField(verbose_name='Contract No')
Bid_Opening = models.CharField(max_length=255, verbose_name='Bid Opening')
Pre_Bid_Conference = models.CharField(max_length=255, verbose_name='Pre Bid Conference')
Non_Refundable_Bidder_Fee = models.CharField(max_length=255, verbose_name='Non Refundable Fee')
Delivery_Period = models.CharField(max_length=255, verbose_name='Delivery Period')
Pdf_fileinvi = models.FileField(max_length=255, upload_to='upload/invitoBid', verbose_name='Upload Pdf File Here')
Date_Upload = models.DateField(auto_now=True)
def __str__(self):
return self.NameOfFile

我想将其传递到 ProjectName 字段

最佳答案

如果您想将查询保存到ProjectName字段中,您可以尝试这样做

form = invitoBidForm(request.POST, request.FILES)
if form.is_valid():
obj = form.save(commit=False)
obj.ProjectName = query
obj.save()
messages.success(request, 'File has been Uploaded')

关于python - 我如何将获取值传递给views.py中的特定模型字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57765401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com