Пример #1
0
def add_book(request):
    post = request.POST
    if post:#getting the form of a new book
        authorName = post.get('Author', '')
        [author,flag] = Author.objects.get_or_create(Name=authorName)#if the author is new, create one
        newbook=Book(
            ISBN=post.get('ISBN', ''),
            Title=post.get('Title', ''),
            Publisher=post.get('Publisher', ''),
            PublishDate=post.get('PublishDate', ''),
            Price=post.get('Price', ''),
            AuthorID=author
        )
        newbook.save()
    return render(request, 'add_book.html', {})
Пример #2
0
def Add(request):
    a=request.GET['a']
    b=request.GET['b']
    c=request.GET['c']
    d=request.GET['d']
    e=request.GET['e']
    f=request.GET['f']
    g=request.GET['g']
    h=request.GET['h']
    i=request.GET['i']
    t= Author(AuthorID=a,Name=b,Age=c,Country=d)
    t.save()
    p=Book(ISBN=e,Title=f,AuthorID=t,Publisher=g,PublishDate=h,Price=i)
    p.save()
    return render_to_response('Add_result.htm')