title: Django view with list (order and pagination) and Delete-function?
body: <p>I have a html-template where I list users Django model objects. This page also have a pagination and links to order the objects. Now I'm thinking of putting a delete-button on each object, which deletes it from the list and database without breaking the order or pagination (returning the current queryset without the deleted object).</p>
  
  <p>I've tried with a delete-view with it's own url but I think the best would be to put it all in the same view to be able to return/handle the order_by and pagination. Something like my pagination links that loads a href like:</p>
  
  <p>"mylist/?page={{ results.next_page_number }}&amp;order_by={{ order_by }}"</p>
  
  <p>But with an additional delete-someID-parameter (what's the preferred method?). I'm not sure if this is the clean (and secure?) way to do this? I'm thinking of checking the objects user against the logged in user also.</p>
  
  <pre><code>deleteid = get_object_or_404(Mymodel, pk=?) #what to do here?
  if deleteid.user == request.user:
      deleteid.delete()
  </code></pre>
  
  <p>I'm thinking right here? I need some guidance to put all this together.</p>
  
  <p>View:</p>
  
  <pre><code>def Mylist(request):
  
      order_by = request.GET.get('order_by', 'somedefault')   
      myobjects_list = Mymodel.objects.filter(user=request.user).order_by(order_by)
      paginator = Paginator(myobjects_list, 5)
  
      page = request.GET.get('page')
      try:
          results = paginator.page(page)
      except PageNotAnInteger:
          results = paginator.page(1)
      except EmptyPage:
          results = paginator.page(paginator.num_pages)
  
      context = {'results ': results, 'order_by': order_by }
      return render_to_response('mylist.html', context, context_instance=RequestContext(request))
  </code></pre>