Skip to content

Instantly share code, notes, and snippets.

@skolo-online
Created August 17, 2021 07:52
Show Gist options
  • Save skolo-online/038577e8719cfa76e090395bb485d7ed to your computer and use it in GitHub Desktop.
Save skolo-online/038577e8719cfa76e090395bb485d7ed to your computer and use it in GitHub Desktop.
Django Invoicing app - View function
@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