title: How to reverse_lazy to a view/url with variable?
body: <p>I've got a <code>DeleteView</code> I use for removing objects from a model. It is launched via a button in a table. It works fine.</p>
  
  <pre><code>class DeleteAssignment(DeleteView):
    model = Assignment
    success_url = reverse_lazy('company')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RxUB6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RxUB6.png" alt="Screenshot"></a></p>
  
  <p>I just want to have it return to it's parent view on success. I currently have it redirecting to the parent's parent (<code>company</code>), as this view doesn't require a variable. This would be simple, but the parent view requires a variable <code>farm_id</code> to render, this is captured from the url like "/farm/18"</p>
  
  <pre><code>url(r'^farm/(?P&lt;farm_id&gt;.+)', views.farm, name='farm'),
  </code></pre>
  
  <p>I've solved this with forms on the page by having them redirect to the view <code>farm</code> with the variable <code>farm_id</code>.</p>
  
  <pre><code>return redirect(farm, farm_id=farm_id)
  </code></pre>
  
  <p>How could I do this with the <code>success_url</code> for my <code>DeleteView</code>?</p>
  
  <p>Example for nickie:</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code> @login_required
      def farm(request, farm_id=None):
          user = request.user
          company_id = user.profile.company_id
          farm_id = farm_id
          farm_filter = Farm.objects.filter(farm=farm_id)
          farm_current = farm_filter[0]
          # farm_company =
          serial_filter = Sensor.objects.filter(assignment__farm__company_id__isnull=True)
          assignment_filter = Assignment.objects.filter(farm=farm_id)
          farm_instance = Farm.objects.get(farm=farm_filter[0].farm)
          update_farm_form = UpdateFarmForm(instance=farm_instance)
          assign_sensor_form = AssignmentForm()
  
          if request.method == 'POST' and 'updatefarm' in request.POST:
              update_farm_form = UpdateFarmForm(request.POST, instance=farm_instance)
              if update_farm_form.is_valid():
                  update_farm_form.save()
                  return redirect(farm, farm_id=farm_id)
          else:
              if request.method == "POST" and 'assignsensor' in request.POST:
                  assign_sensor_form = AssignmentForm(request.POST)
                  if assign_sensor_form.is_valid():
                      assignment = assign_sensor_form.save()
                      if user.is_staff is True:
                          assignment.company_id = farm_filter[0].company_id
                      else:
                          assignment.company_id = user.profile.company_id
                      assignment.save()
                      return redirect(farm, farm_id=farm_id)
                  else:
                      assign_sensor_form = AssignmentForm(request.POST)
          return render(request, 'users/farm_template.html', {'company_id': company_id, 'farm_filter': farm_filter, 'farm_current': farm_current, 'serial_filter': serial_filter, 'assignment_filter': assignment_filter, 'update_farm_form': update_farm_form, 'assign_sensor_form': assign_sensor_form})
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>from django.conf.urls import url, include
  from django.contrib.auth import views as auth_views
  
  from apps.dashboard import views
  from apps.dashboard.views import DeleteAssignment, DeleteFarm
  
  urlpatterns = [
      url(r'^company/', views.company_view, name='company'),
      # url(r'^test/', views.test),
      # url(r'^test2/', views.test2, name='test2'),
      # url(r'^farms/', views.add_farms),
      url(r'^manual-signup/', views.signup_manual),
      url(r'^signup/(?P&lt;company_id&gt;.+)', views.signup_company),
      url(r'^settings/', views.update_profile),
      url(r'^create-company/', views.create_company),
      url(r'^create-sensor/', views.create_sensor),
      url(r'^assign-sensor/', views.assign_sensor),
      url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name='login'),
      url(r'^logout/$', auth_views.logout, {'next_page': '/login'}, name='logout'),
      url(r'^$', views.main),
      # url(r'^company/(?P&lt;company_id&gt;.+)/farm/(?P&lt;farm_id&gt;.+)', views.farm),
      url(r'^farm/(?P&lt;farm_id&gt;.+)', views.farm, name='farm'),
      url(r'^unit/(?P&lt;sensor_id&gt;.+)', views.unit),
      # url(r'^company/(?P&lt;company_id&gt;.+)', views.company),
      url(r'^download/', views.download),
      # url(r'^export/xls/$', views.export_users_xls),
      url(r'^live/', views.live),
      url(r'^data/', views.data),
      url(r'^debug/', views.debug),
      url(r'^delete-assignment/(?P&lt;pk&gt;\d+)/$', DeleteAssignment.as_view(), name='delete-assignment', ),
      url(r'^delete-farm/(?P&lt;pk&gt;\d+)/$', DeleteFarm.as_view(), name='delete-farm', ),
      url(r'^', include('django.contrib.auth.urls'))
  ]
  </code></pre>
  
  <p>This is view redirects to itself upon successful form submission. This reloads tables based on the user submission without having to deal with js for now.</p>
  
  <p>The <code>farm_id</code> in <code>return redirect(farm, farm_id=farm_id)</code> is captured from the url, via the appropriate line in <strong>urls.py</strong> <code>url(r'^farm/(?P&lt;farm_id&gt;.+)', views.farm, name='farm'),</code></p>
  
  <p>This is all I want to do with the delete view, instead of the success url simply being a view, a view with a variable like I did above.</p>