[Answered ]-Populate Django form from 3rd party POST with different field names

1πŸ‘

βœ…

You can create your own dict for form init:

if request.method == 'POST':
    if need_to_convert_post(request):
        post = {
            'field1': None,
            'field2': None,
            'field3': None,
        }
        post['field1'] = request.POST.get('SomeOtherField1', None)
    else:
        post = request.POST
    form = Form1(post)
else:
    form = Form1()

and detect when you need to change post:

def need_to_convert_post(request):
    if 'uniqueCheckField' in request.POST:
        return True
    return False
πŸ‘€Vital Belikov

1πŸ‘

For tidyness, you could use request.POST['status'] = request.POST.pop('FinalStatus'), otherwise it’s perfectly fine to use your approach.

Leave a comment