Return to a page with completed form

Asked

Viewed 523 times

1

I’m using Django and I have to implement the following flow:

The user fills in the information of a new exam, clicks on attach an old exam, goes to the exam search screen, selects the desired exam and needs to return to the new exam registration page (with the information that had already completed).

I’ve done the redirect link part, but how can I:

1) Keep the registration page data filled when redirecting to others. I searched for a django cache framework, but I don’t know if that’s right.

2) Pass the selected exam id to the other page.

I’m not going to add code because it’s more of a conceptual issue, so if you can pass me any example of something like this, or some term that I can search for, it helps a lot.

Edit: I was able to return to the page with the data filled using onclick="location.href = 'javascript:window.history.go(-2)'", which is equivalent to pressing the back button twice. I hope that it will be possible to pass the id.

  • In fact the search for new exams could be done through a modal window where you would search the exam itself and this would be added to the form (or not if the modal window were facade).

  • @Giovanninunes, I also thought about this approach, but already having ready the search screen was asked to go to the same page :

  • Opens in another window, not fucncionaria?

  • Can’t be with page tabs?

  • @Sidon with page tabs creates a copy of the page?

  • 1

    You put whatever you want in tabs in the link I put in the other comment you can "play" a little with the tabs, do this and you will understand

Show 1 more comment

1 answer

0

It may not be the best approach to solving this case, but when the user selects the exam, he saves the exam id on Session, when he returns to the form page, checks if he has an id on Session, loads the object by the id, arrow them with initial on Forms.py and erases that id tab.

You only have to pay attention if the flow is interrupted so id is not set in Session, that is, when you enter this form page, but, not from the selection redirect, delete the id of Session - if you have any.

https://docs.djangoproject.com/pt-br/2.1/topics/http/sessions/

Oh yes, it does not redirect by javascript, it uses what Django offers, one of the cases for example, you can override the save button and continue.

class ClasseAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, changed):
        if '_continue' in request.POST:
            redirect('url_name')
        return super().save_model(request, obj, form, change)

Reference: https://docs.djangoproject.com/pt-br/2.1/topics/http/shortcuts/

  • Really not even the best approach, I would say it’s a 'bad idea''. :-)

  • It is that if you can not change the flow of the screen, this was the only solution that came to mind..

  • Can’t change the "screen flow"? As the Tadeu would say: "Qué q isso rapa?" :-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.