Handle Multiple Forms On One Page Django.How

Author avatar wrote on 02/06/2022

Template in form


View

def handle_translator_forms(request, template="translation/translator.html"):
    if request.method == 'POST':
        if request.POST.get("form_type") == 'update_specialties':

Get record want to update

            record = Translator.objects.get(id=request.POST['translator_id'])

Change the fields you want to change

            record.speciality_1 = request.POST['speciality_1']
            record.speciality_2 = request.POST['speciality_2']
            record.speciality_3 = request.POST['speciality_3']
            record.speciality_4 = request.POST['speciality_4']
            record.speciality_5 = request.POST['speciality_5']
            record.save(update_fields=['field', 'field2'])

        elif request.POST.get("form_type") == 'add_language':

Handle Elements from second Form

            '''b = Blog(name='Beatles Blog', tagline='All the latest Beatles news.')
            b.save()'''
            return 1

        elif request.POST.get("form_type") == 'update_language':

Handle Elements from second Form

            return 1

        elif request.POST.get("form_type") == 'add_prices':

Handle Elements from second Form

            return 1

        elif request.POST.get("form_type") == 'update_prices':

Handle Elements from second Form

            return 1
        else:
            return 0