Esempio n. 1
0
def formUser(request):
    
    author = Author.objects.all()
    
    if request.method == 'POST':
        form = AuthorForm(request.POST)
        
        if form.is_valid():
            new_author = form.save(commit=False)
            new_author.some_field = 'some_value'
            new_author.save()
            form.save_m2m()
            print('Válido')
#             HttpResponseRedirect(reverse('form:form-user'))
    else:
        form = AuthorForm()
        print('Inválido')
    
    return render(request, 'formulario/form-user.html', {
                                                         
         "author": author,
         "form": form,
    })          
Esempio n. 2
0
from django.test.client import Client

from formulario.models import AuthorForm


client = Client();
f = AuthorForm()

new_author = f.save(commit=False)

new_author.some_field = 'some_value'

new_author.save()

f.save_m2m()