Created
August 17, 2021 07:52
-
-
Save skolo-online/038577e8719cfa76e090395bb485d7ed to your computer and use it in GitHub Desktop.
Django Invoicing app - View function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def clients(request): | |
context = {} | |
clients = Client.objects.all() | |
context['clients'] = clients | |
if request.method == 'GET': | |
form = ClientForm() | |
context['form'] = form | |
return render(request, 'invoice/clients.html', context) | |
if request.method == 'POST': | |
form = ClientForm(request.POST, request.FILES) | |
if form.is_valid(): | |
form.save() | |
messages.success(request, 'New Client Added') | |
return redirect('clients') | |
else: | |
messages.error(request, 'Problem processing your request') | |
return redirect('clients') | |
return render(request, 'invoice/clients.html', context) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment