[Fixed]-Django listview clone selected record

1๐Ÿ‘

โœ…

Iโ€™ve done this with a simple method in views.py. Simply retrieve the record, blank out its id then save and open it. Something like

def create_new_version(request) :
    record = models.MyDocument.objects.filter(id=request.GET['id'])[0]
    record.id = None
    record.save()
    return http.HttpResponseRedirect(reverse('edit-mydocument', kwargs={'pk':record.id}))

where MyDocument is your model and edit-mydocument is your UpdateView. Just call this using the id of the document that you want to copy as the id parameter on the GET.

๐Ÿ‘คElPedro

Leave a comment