Advertisement
MartinYanchev-99

views.py

Mar 26th, 2021
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. from django.shortcuts import render
  2. from django.contrib import messages
  3.  
  4. from .forms import AddSleepForm
  5. from .models import Sleep
  6. # Create your views here.
  7. def sleep_tracker(request):
  8.     form = AddSleepForm(instance = request.user)
  9.     if request.method == 'POST':
  10.         form = AddSleepForm(request.POST,instance = request.user)
  11.         if form.is_valid():
  12.             form.save()
  13.         else:
  14.             messages.error(request,"Please fill all the fields")
  15.    
  16.     sleep_data = Sleep.objects.all()
  17.     context = {'form': form,'sleep_data': sleep_data}
  18.     return render(request,'sleep_tracker/dashboard.html',context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement