[Answered ]-Django return different class-based view according to whether an object has been created

2👍

If you already have created working CreateView and UpdateView (I’m assuming we are talking about django’s View subclasses), set proper templates inside of them, and then return correct views:

def getArchived(request):
    q = request.GET.get('q',None)
    try:
        archived = Archivedfolder.objects.get(folder=q)
        return DataUpdate.as_view()(
            request,
            is_list=is_list,
            table=table,
            pk=pk
        ) 
    except Archivedfolder.DoesNotExist:
        return CreateView.as_view()(request)

EDIT

If you have is_list, table and pk parameters in your url, you’d get them in View as parameters next to request. Also you use them as kwargs, so don’t forget about argument’s name. Edited code above.

Leave a comment