[Answer]-How to reference the newly created object using FormView

1👍

this is really straight forward, given an url in the league namespace like

url(r'^league/editleague/(?P<id>\d+>)$', LeagueView.as_view(), name='edit')

you should edit the form_valid method in this way:

from django.shortcuts import redirect

class LeagueView(FormView):
    template_name = 'leagueapp/addleague.html'
    form_class = LeagueForm

    def form_valid(self, form):
        newleague = form.save()
        return redirect('league:edit', id=newleague.id)
👤DRC

Leave a comment