예제 #1
0
파일: views.py 프로젝트: cozybed/lab4-1
def save(request):
    post = request.POST
    error_Response = render(request, 'books/error.html')
    success_Response = render(request, 'books/success.html')
    post_ISBN = post['ISBN']
    if_new_author = 0
    try:
        post_author = models.author.objects.get(name=post['Author'])
    except:
        post_author = models.author()
        post_author.name = post["Author"]
        post_author.age = "0"
        post_author.authorID = str(len(models.author.objects.all()))
        post_author.country = "China"
        post_author.save()
        if_new_author = 1
    post_Title = post['Title']
    post_Publisher = post['publisher']
    post_Date = post['publishDate']
    post_Price = post['price']
    newBook = models.books()
    newBook.author = post_author.authorID
    newBook.ISBN = post_ISBN
    newBook.Title = post_Title
    newBook.publishDate = post_Date
    newBook.publisher = post_Publisher
    newBook.price = post_Price
    try:
        newBook.save()
    except:
        return error_Response
    if if_new_author:
        context = {'new_author': post_author}
        return render(request, "books/add_author.html", context)
    return success_Response
예제 #2
0
파일: views.py 프로젝트: 153370771/lab4
def authoradd(request):
    if request.POST:
        author_lst=author(authorid=request.POST['authorid'],name=request.POST['name'],age=request.POST['age'],country=request.POST['country'])
        author_lst.save()
        
        return render_to_response('authoradd.html')
    else:
        return render_to_response('index.html')
예제 #3
0
파일: views.py 프로젝트: cozybed/lab4-1
def single(request):
    isbn = request.GET['ISBN']
    error_Response = render(request, 'books/error.html')
    try:
        latest_book_list = models.books.objects.get(ISBN=isbn)
    except:
        return error_Response
    latest_book_list = [latest_book_list]
    single_book = latest_book_list[0]
    try:
        single_author = models.author.objects.get(authorID=single_book.author)
    except:
        single_author = models.author()

    context = {'latest_book_list': latest_book_list, 'single_book': single_book, 'single_author':single_author}
    return render(request, 'books/singleBook.html', context)
예제 #4
0
def authors_to_author(author):
    return models.author(id=author.id, gid=author.gid, name=author.name)
def authors_to_author(author):
    return models.author(id=author.id, gid=author.gid, name=author.name)