soy nuevo en Django, así que siento por mi pregunta novato
Tengo un modelo y tengo que dejar que los datos de usuario de edición en su interior el uso de formularios de Django o de cualquier otra manera . cómo editar los datos del modelo usando formas django
mira la imagen de arriba, quiero mostrar este formulario listo para rellenar con los datos y dejar que el usuario lo actualice.
¿cuál es la mejor manera de hacer esto?
EDIT: Aquí está mi código views.py
def exam_Edit(request,examName,number=0):
numner = int(number)
number = int(number)
questionNo = int(numner)
Myexam = models.Exam.objects.get(name = examName)
QuestionsAll = models.Question.objects.filter(exam = Myexam)
myQeustion = Question.objects.filter(exam = Myexam)[nextQuestion]
answer1 = models.Asnwers.objects.filter(question=myQeustion)[0]
answer2 = models.Asnwers.objects.filter(question=myQeustion)[1]
answer3 = models.Asnwers.objects.filter(question=myQeustion)[2]
answer4 = models.Asnwers.objects.filter(question=myQeustion)[3]
# HERE IS MY PROBLEM : the line below creates a form with a data but it doesn't save it to the save object
form = QuestionsEditForm(initial = {'questionText':myQeustion.__unicode__() , 'firstChoiceText':answer1.__unicode__(),'secondChoiceText':answer2.__unicode__(),'thirdChoiceText':answer3.__unicode__(),'forthChoiceText':answer4.__unicode__()})
if request.method =='POST':
#if post
if form.is_valid():
questionText = form.cleaned_data['questionText']
Myexam = Exam.objects.get(name = examName)
myQeustion.questionText = form.cleaned_data['questionText']
answer1.answerText = form.cleaned_data['firstChoiceText']
answer1.save()
answer2.answerText = form.cleaned_data['secondChoiceText']
answer2.save()
answer3.answerText = form.cleaned_data['thirdChoiceText']
answer3.save()
answer4.answerText = form.cleaned_data['forthChoiceText']
answer4.save()
variables = RequestContext(request, {'form':form,'examName':examName,'questionNo':str(nextQuestion)})
return render_to_response('exam_edit.html',variables)
favor ayuda
¿Qué parte de http://docs.djangoproject.com/en/1.3/ref/forms/api/#bound-and-unbound-forms era confuso? ¿Puedes ser mas específico? ¿Puedes publicar tu código? –
¿Por qué no publicas parte del código que ya tienes? Esto es tan simple como devolver un objeto de modelo "Pregunta" con campos que llene con texto predeterminado. – Nix
Solo un aviso, pero las últimas 2 líneas de tu código no están sangradas. – john2x