Exemple #1
0
def add_review(request):
    user = User.objects.get(id=1)
    new = News.objects.get(id=1)
    review = Review(user=user,
                    new=new,
                    # 创建时间
                    create_time=datetime.datetime.now(),
                    )
    review.save()
    return HttpResponse('success')
Exemple #2
0
def new_review(request):
    if request.method == "GET":
        form = ReviewForm()
        return render(request, "new_review.html", {"form":form})
    else:
        form = ReviewForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            review = form.cleaned_data['review']
            name = form.cleaned_data['name']
            new = Review(title=title, review=review, name=name, createdDate=datetime.now())
            new.save()
            return HttpResponseRedirect(reverse('all_reviews'))
        else:
            return render(request, "new_review.html", {"form":form})
Exemple #3
0
def new_review(request):
    # someone wants to create a new review
    if request.method == "GET":
        form = ReviewForm()
        return render(request, "new_review.html", {"form": form})
    else:
        # someone submitted the form so we need to save the data
        form = ReviewForm(request.POST)

        if form.is_valid():
            title = form.cleaned_data["title"]
            review = form.cleaned_data["review"]
            name = form.cleaned_data["name"]
            new = Review(title=title, review=review, name=name, created_date=datetime.now())
            new.save()

            return HttpResponseRedirect(reverse("all_reviews"))

        else:
            return render(request, "new_review.html", {"form": form})
def insert_reviews(request):
    reviews_page = request.GET.get("review_page", 0)
    reviews = Review.get_review(reviews_page)
    return {"reviews": reviews, "reviews_page": reviews_page}