Django, query and post

0

I need to fetch data from external DB, search for a specific ID, then populate some fields and then save a ModelForm. Something like this:

def add_form_atendimento(request):
    if request.method == 'POST':
        q = request.POST.get('q', '')

        branchs = Branch.objects.filter(
            Q(uniorg__icontains=q) |
            Q(name__icontains=q))

        if branchs == 0:
            type = '<option value="installation">Instalação</option>'
            tipo = 'Instalação'
        else:
            type = '<option value="installation">Instalação</option>'
            tipo = 'Instalação'

        form = AddFormAtendimento(request.POST or None)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect("/")
        ...
        ...

The problem is that by bringing the result I already sent via POST, at the beginning of the function, how do I proceed to save my form data? Before arriving at this function I already made a form query using POST.

    
asked by anonymous 31.07.2018 / 13:47

0 answers