2

I would like to enter the fields' values after my ModelForm instance is posted. I have three forms and every step one form is posted. I would like to make a logging system to save data to database until the user saves finishes all three forms. One of the forms is a ModelForm.

In my forms.py file:

class StepOne(forms.ModelForm):
    class Meta:
        model = Article
        fields = ['name', 'difficulty', 'content']

I would like to access the form's field values after it has been posted in my view class, like this:

class MyView(views.View):
    def post(self, request):
        form = StepOne(request.POST)
        content = form.content
        difficulty = form.difficulty
        ....

Is there such thing possible?

1
  • 1
    Really you should use a FormView and do this logic in the form_valid method. Commented Dec 23, 2015 at 18:54

1 Answer 1

6

You need to call form.is_valid() in order to access the form data:

form = StepOne(request.POST)
if form.is_valid():
    content = form.cleaned_data['content']
    difficulty = form.cleaned_data['difficulty']

django doc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.