title: simplest way to save or display data for form in django
body: <p>I have the following code in a view for the purpose of handling the display, save, or update of data.</p>
  
  <p>The code looks unruly and seems like it can be simplified.  What can I do to accomplish the requirements above while not repeating myself and have as simple logic as possible?</p>
  
  <pre><code>def details(request, pk=None):
      customer = request.user.customer
      existing_detail = Detail()
      detail_queryset = Detail.objects.filter(customer_id=customer.id)
  
      if detail_queryset:
          existing_detail = detail_queryset[0]
  
      if request.method == 'POST':
          form = detailForm(request.POST)
          if form.is_valid():
              pay_out = form.cleaned_data['title']
              if detail_queryset:
                  existing_detail.title = title
                  existing_detail.save()
              else:
                  detail = Detail(customer=customer, payoutType=title)
                  detail.save()
              return HttpResponseRedirect('/settings/details/')
      else:
          if detail_queryset:
              form = detailForm(initial={'title': existing_detail.title})
          else:
              form = detailForm()
  
      context = {
          'title':'details',
          'view':'detail',
          'form': form
      }
      return render(request, 'customers/detail.html', context)
  </code></pre>