I have a simple UpdateView which updates instances of my Profile model.
class ProfileUpdateView(UpdateView):
model = Profile
fields = ['first_name', 'last_name']
It's working fine both GET and POST, but since the GET uses an url parameter, I want also the redirect_url to redirect to the updated profile.
My current urls.py:
from profiles.views import ProfileUpdateView
urlpatterns = [
path('self/<slug:slug>', ProfileUpdateView.as_view(success_url='/'), name='self_profile')
]
It is currently redirecting to the main url, but I don't figure out how to make the redirect_url parameter redirect to the profile modified on the handled POST.
Let's say I do http://localhost:8000/profiles/self/demo, (GET), then I modify my first_name and submit the request. I want the redirection to go to /profiles/self/demo again.
I know I could override def post() on the view and achieve it, but since I only want to deal with the redirection I wanted to know if exists any other elegant solution.
EDIT:
Additional info: the slug url parameter will always be request.user in this case (since I use other view (a DetailView) to see other users' profiles).
Thanks!!