Django - Mixing ListView and CreateView

Do not mix list and update views.
Instead, create two separate views for these tasks:

List view displays the list and a web form with action URL pointing to the create view.
Create view accepts POST data and

  • displays form with error message in case of failure;
  • redirects to the list view in case of success.

Also I've tried to use class-based views and found that they are too complex.
I think it is much easier to use old-style function views.


I use a lot of views that involve a form and a list of objects. Rather than trying to mixin things I just add the queryset into the context data as below.

class UploadFileView(CreateView):
    form_class = UploadFileForm
    success_url = 'listview'
    template_name = 'textfrompdf/index.html'

    def get_context_data(self, **kwargs):
        kwargs['object_list'] = PdfFile.objects.order_by('id')
        return super(UploadFileView, self).get_context_data(**kwargs)