(request, pk)
return redirect(new_report)
Copy a report including related fields
Copy a report including related fields
Copy a report including related fields
def create_copy(request, pk):
    """ Copy a report including related fields """
    report = get_object_or_404(Report, pk=pk)
    new_report = duplicate(report, changes=(
        ('name', '{0} (copy)'.format(report.name)),
        ('user_created', request.user),
        ('user_modified', request.user),
    ))
    # duplicate does not get related
    for display in report.displayfield_set.all():
        new_display = copy.copy(display)
        new_display.pk = None
        new_display.report = new_report
        new_display.save()
    for report_filter in report.filterfield_set.all():
        new_filter = copy.copy(report_filter)
        new_filter.pk = None
        new_filter.report = new_report
        new_filter.save()
    return redirect(new_report)
def create_copy ( request , pk ) : report = get_object_or_404 ( Report , pk = pk ) new_report = duplicate ( report , changes = ( ( 'name' , '{0} (copy)' . format ( report . name ) ) , ( 'user_created' , request . user ) , ( 'user_modified' , request . user ) , ) ) # duplicate does not get related for display in report . displayfield_set . all ( ) : new_display = copy . copy ( display ) new_display . pk = None new_display . report = new_report new_display . save ( ) for report_filter in report . filterfield_set . all ( ) : new_filter = copy . copy ( report_filter ) new_filter . pk = None new_filter . report = new_report new_filter . save ( ) return redirect ( new_report )