def edit(request): template = 'main/edit.html' if request.method == 'POST': form = CourseForm(request.POST) logger.debug(request.POST) message = None if form.is_valid(): form.save() message = 'Dziękujemy kurs został utworzony.' context = RequestContext(request, {'form': form, 'message': message}) response = render_to_string(template, context) return HttpResponse(response, 'text/html') return render_to_response(template, {'form': CourseForm()})
def get(self, request): form = CourseForm() posts = Course.objects.all() print(posts) return render(request=request, template_name="main/course.html", context={'form': form})
def get(self, request): form = CourseForm() posts = Course.objects.get(id=my_id).order_by('name') print(posts) return render(request=request, template_name="main/course.html", context={'posts': posts})
def review(request): my_form = CourseForm() # course_form=SchoolCourseForm() course_list = SchoolCourse.objects.all() if request.method == "POST": my_form = CourseForm(request.POST) if my_form.is_valid(): print(my_form.cleaned_data) # Course.objects.create(my_form.cleaned_data) my_form.save() return render(request=request, template_name="main/course.html", context={ 'my_form': my_form, 'course_list': course_list }) else: print(my_form.errors) #once u make a review, it should direct u to the class page return render( request= request, #so u can reference things inside your template to do with the user template_name="main/review.html", context={ "form": my_form, 'course_list': course_list })
def review(request): my_form = CourseForm() if request.method == "POST": my_form = CourseForm(request.POST) if my_form.is_valid(): print(my_form.cleaned_data) Course.objects.create(my_form.cleaned_data) my_form.save() else: print(my_form.errors) return render( request= request, #so u can reference things inside your template to do with the user template_name="main/review.html", context={"form": my_form})
def create_course(request): form = CourseForm() # If user inputs comment if request.method == 'POST': form = CourseForm(request.POST) # If input is valid if form.is_valid(): # Save the form form.save(commit=True) return redirect('/main/courses/') else: print(form.errors) return render(request, 'main/create_course.html', {'form': form})