I know i should probably not open another thread for this question because it has been asked and answered so many times here.Yes I've worked through the tutorials and browsed the web a lot - what I have is mix of what I'm finding here and at other sites but Im having a hard time saving form inputs in the database.
some one should please come to my rescue i have been trying to get this done for 3 days now, its very frustrating.
here are my codes
models.py class QuestionBank(models.Model):
First_Semester ='First_Semester'
Second_Semester ='Second_Semester'
Semesters = ((First_Semester, 'First_Semester'),(Second_Semester, 'Second_Semester'))
level = models.ForeignKey(ClassLevel)
CourseTitle = models.CharField(max_length=50, null=False)
CourseCode = models.CharField(max_length=10, null=False )
CourseUnit = models.IntegerField()
Semester = models.CharField(max_length=20, choices=Semesters, default="Select_Semester")
Date = models.DateField()
question_papers = models.FileField(upload_to = 'QuestionPapers')
def __str__(self):`enter code here`
return '%s %s %s %s %s %s %s' %(self.level, self.CourseTitle, self.CourseCode, self.CourseUnit, self.Semester, self.Date, self.question_papers )
forms.py
class QuestionBankForm(forms.ModelForm):
class Meta:
model = QuestionBank
fields = ('level', 'CourseTitle', 'CourseCode', 'CourseUnit', 'Semester', 'Date', 'question_papers' )
views.py
def uploadQpapers(request):
context = RequestContext(request)
if request.method == 'POST':
Qpapers = QuestionBankForm(data=request.POST)
if Qpapers.is_valid():
Qpapers.save()
return render_to_response("Qbank/uploadQpapers.html", {'Qpapers':Qpapers}, context)
else:
return HttpResponse('INVALID')
i want to be able to upload past questions and save it to database but its not working there are no error messages becuase only the else statement is being return any time i try to save, I really dont know what to do i need some one to help me. thanks in advance
print request.POSTwhether all fields are present or not