title: Django Crud Operations in Single View
body: <p>My online marketing department tracks thousands of rows of email and analytic marketing data and I am building a tool that we can use in-house to manage the data so we can run multiple queries to produce reports.</p>
  
  <p>The CRUD operations are working normally, but with so much data to enter, its inefficient to have ticket_form.html, ticket_list.html and a ticket_confirm_delete.html views and templates.  My list data is in table format, so what I would like to do is combine the operations under a single view so I can add a column at the end of my table with icons to add, update and delete the row.  Thank you for your help.</p>
  
  <p>My current views, I'd like to combine:</p>
  
  <pre><code>class TrafficForm(ModelForm):
      class Meta:
          model = Traffic
          fields = ['sessions', 'new_users', 'reminder', 'campaigns', 'new_sales', 'sales_renewals']
  
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self.fields['sessions'].widget.attrs.update({
              'placeholder': 'Sessions',
              ...
          })
  
          for field in iter(self.fields):
              self.fields[field].widget.attrs.update({
                  'class': 'form-control placeholder-no-fix'
              })
  
  
  def traffic_create(request, template_name='traffic_form.html'):
      form = TrafficForm(request.POST or None)
      if form.is_valid():
          form.save()
          return redirect('traffic_list')
      return render(request, template_name, {'form': form})
  
  
  def traffic_list(request, template_name='traffic_list.html'):
      traffic = Traffic.objects.all()
      data = {}
      data['object_list'] = traffic
      return render(request, template_name, data)
  
  
  def traffic_update(request, pk, template_name='traffic_form.html'):
      traffic = get_object_or_404(Traffic, pk=pk)
      form = TrafficForm(request.POST or None, instance=traffic)
      if form.is_valid():
          form.save()
          return redirect('traffic_list')
      return render(request, template_name, {'form': form})
  
  
  def traffic_delete(request, pk, template_name='traffic_confirm_delete.html'):
      traffic = get_object_or_404(Traffic, pk=pk)
      if request.method == 'POST':
          traffic.delete()
          return redirect('traffic_list')
      return render(request, template_name, {'object': traffic})
  </code></pre>