需要有关“ ProjectName_id”列中的空值的帮助违反了非空约束,这是django的新增功能
我希望我的ProjectName_id(外键)与用户在我的
中选择的ID相同
majordetails = ProjectNameInviToBid.objects.get(id = sid)请帮助我...
我的模型视图
class ProjectNameInviToBid(models.Model):
ProjectName = models.CharField(max_length=255, verbose_name='Project Name', null=True)
DateCreated = models.DateField(auto_now=True)
class InviToBid(models.Model):
today = date.today()
ProjectName = models.ForeignKey('ProjectNameInviToBid', on_delete=models.CASCADE)
NameOfFile = models.CharField(max_length=255, verbose_name='Name of File')
我的views.py
def project_name_details(request, sid):
majordetails = ProjectNameInviToBid.objects.get(id=sid)
if request.method == 'POST':
form = invitoBidForm(request.POST, request.FILES)
if form.is_valid():
majordetails = InviToBid.ProjectName
form.save()
messages.success(request, 'File has been Uploaded')
else:
form = invitoBidForm()
args = {
'majordetails': majordetails,
'form': form
}
return render(request,'content/invitoBid/bacadmininvitoBid.html', args)
class ProjectNameInviToBidForm(ModelForm):
class Meta:
model = ProjectNameInviToBid
fields = ('ProjectName',)
class invitoBidForm(ModelForm):
class Meta:
model = InviToBid
fields = ('NameOfFile', 'Contract_No', 'Bid_Opening',
'Pre_Bid_Conference', 'Non_Refundable_Bidder_Fee',
'Delivery_Period',
'Pdf_fileinvi')