vendredi 7 août 2015

django - how to implement a 2-step publish mechanism

I'm new to both web development and django so maybe that's a noob question.

I want to do the following:

  1. Ask user to fill some form and submit it.
  2. Then, parse and format the content and display it back to the user to let him verify it.
  3. User can accept the result or go back to the previous view, update data and resend.

This is as far as I can think:

views.py

def add_content(request):
    if request.method == 'POST':
        form = AddContentForm(request.POST)
        if form.is_valid():
            content = form.save(commit=False)
            return verify_content(request, content)
    else:
        form = AddContentForm()
    return render(request, 'myapp/add_content.html', {'form' : form})

def verify_content(request, content):
    return render(request, 'myapp/verify_content.html', {'content' : content})

The verify_content template will obviously contain two buttons ('back', 'ok'), but I don't know how to pass the content object to a view for saving it in the db, or send it back to the previous view from there. Should I use js? Can i do it with just server side code?

Maybe my whole logic is wrong. Should I save the object in the db before verification and then delete it if needed (sounds ugly)? What is a good way to implement this?

Thanks in advance for your time.




Aucun commentaire:

Enregistrer un commentaire