当前位置: 首页>>代码示例>>Python>>正文


Python Book.save方法代码示例

本文整理汇总了Python中models.Book.save方法的典型用法代码示例。如果您正苦于以下问题:Python Book.save方法的具体用法?Python Book.save怎么用?Python Book.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Book的用法示例。


在下文中一共展示了Book.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_default_creation

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
    def test_default_creation(self):
        "Objects created on the default database don't leak onto other databases"
        # Create a book on the default database using create()
        Book.objects.create(title="Pro Django",
                            published=datetime.date(2008, 12, 16))

        # Create a book on the default database using a save
        dive = Book()
        dive.title="Dive into Python"
        dive.published = datetime.date(2009, 5, 4)
        dive.save()

        # Check that book exists on the default database, but not on other database
        try:
            Book.objects.get(title="Pro Django")
            Book.objects.using('default').get(title="Pro Django")
        except Book.DoesNotExist:
            self.fail('"Dive Into Python" should exist on default database')

        self.assertRaises(Book.DoesNotExist,
            Book.objects.using('other').get,
            title="Pro Django"
        )

        try:
            Book.objects.get(title="Dive into Python")
            Book.objects.using('default').get(title="Dive into Python")
        except Book.DoesNotExist:
            self.fail('"Dive into Python" should exist on default database')

        self.assertRaises(Book.DoesNotExist,
            Book.objects.using('other').get,
            title="Dive into Python"
        )
开发者ID:arnav,项目名称:django,代码行数:36,代码来源:tests.py

示例2: add

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def add(request):
    if request.POST:
        post = request.POST
        if (
            post["ISBN"]
            and post["Title"]
            and post["AuthorID"]
            and post["Publisher"]
            and post["PublishDate"]
            and post["Price"]
        ):
            post = request.POST
            new_book = Book(
                ISBN=post["ISBN"],
                Title=post["Title"],
                AuthorID=post["AuthorID"],
                Publisher=post["Publisher"],
                PublishDate=post["PublishDate"],
                Price=post["Price"],
            )
            new_book.save()

        #
        #        new_author = Author(
        #        AuthorID = post["AuthorID"],
        #        Name = post["Name"],
        #        Age = post["Age"],
        #        Country = post["Country"])
        #        new_author.save()
        else:
            return HttpResponse("Please full all information.")
    return render_to_response("add.html")
开发者ID:clllyw,项目名称:lab4,代码行数:34,代码来源:views.py

示例3: loaddir

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def loaddir(directory, clear=False):
    if clear:
        Book.objects.all().delete()

    queue = os.listdir(directory)
    while queue:
        next = queue.pop()
        if next[0] == '.': continue
        if next in ('categories', 'template'): continue
        next = path.join(directory, next)
        if path.isdir(next):
            queue.extend([
                path.join(next,f) for f in os.listdir(next)
                ])
            continue

        filecontent = file(next).read()
        header, content = filecontent.split('\n---\n')
        header = yaml.load(header)
        content = preprocess_rst_content(content)
        review_date = parsedate(header['review_date'])
        review_date = time.strftime('%Y-%m-%d', review_date)
        B = Book(slug=header['slug'], title=header['title'], booktitle=header['booktitle'], author=header['author'], content=content, review_date=review_date)
        B.save()
        for c in header.get('tags','').split():
            B.tags.add(tag_for(c))
开发者ID:becomingGuru,项目名称:django-gitcms,代码行数:28,代码来源:load.py

示例4: add_book

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def add_book(request):
    """ 添加书籍"""
    if request.POST:
        post = request.POST
        flag = 0
        name_Set = post["authorname"]
        author_name =Author.objects.filter(name = name_Set)
        if(len(author_name) == 0):
            flag = 0
            book_count = Book.objects.all().count()
            book_sum=Context({"Book_count":book_count, "flag":flag})
            return render_to_response("addbook.html",book_sum)
        else:
            author_id =Author.objects.get(name = name_Set)
            new_book = Book(
                ISBN=post['ISBN'],
                Title = post['Title'],
                Publisher=post['Publisher'],
                PublishDate = post['PublishDate'],
                Price = post['Price'],
                Authorname = post['authorname'],
                Authorid = author_id)
            new_book.save()
            flag = -flag
            book_count = Book.objects.all().count()
            book_sum=Context({"Book_count":book_count,"flag":flag})
            return render_to_response("addbook.html",book_sum)   
    else:
        flag = 0
        book_count = Book.objects.all().count()
        book_sum=Context({"Book_count":book_count,"flag":flag})
        return render_to_response("addbook.html",book_sum)
开发者ID:jingyihiter,项目名称:lab3-R1-R7-,代码行数:34,代码来源:views.py

示例5: add_book

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def add_book(request):
    if request.method =="POST":
        form = newBook(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            try:
                author =  Author.objects.get(Name = cd["Author"])
            except:
                request.session["ISBN"] = cd["ISBN"]
                request.session["Title"] = cd["Title"]
                request.session["Publisher"] = cd["Publisher"]
                request.session["PublishDate"] = (str)(cd["PublishDate"])
                request.session["Price"] = (str)(cd["Price"])
                return HttpResponseRedirect("/add_author/?author=%s"%cd["Author"])  
            b = Book(ISBN = cd["ISBN"],
                     Title = cd["Title"],
                     AuthorID = author,
                     Publisher = cd["Publisher"],
                     PublishDate = cd["PublishDate"],
                     Price = cd["Price"]
                     )
            b.save()
            return HttpResponseRedirect("/success/")
    else:
        form = newBook()
    return render_to_response("add_book.html",{"form":form})
开发者ID:stafary,项目名称:lab4,代码行数:28,代码来源:views.py

示例6: update_books

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def update_books(books = get_books()):
    opener = urllib2.build_opener()
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    for book in books:
        try:
            b = Book.objects.filter(title=book['title']).count()
            print '>>>', b
            if not b:
                b = Book()
                b.title = book['title']
                author = book['author']
                last_name = author.split(' ')[-1]
                first_name = ' '.join(author.split(' ')[:-1])
                try:
                    author = Author.objects.get(first_name=first_name, last_name=last_name)
                except:
                    author = Author(first_name=first_name, last_name=last_name)
                    author.save()
                b.author = author
                b.external_url = 'http://en.wikipedia.org'+book['link']
                try:
                    content = opener.open('http://en.wikipedia.org'+book['link']).read()
                    s = Soup(content)
                    info = s.find('table', {'class':'infobox'})
                    img = info.find('img')
                    if img:
                        b.image = 'http:'+img.get('src')
                except:
                    print "IMAGE FAILED FOR", book
                b.save()
        except Exception, e:
            print e
            print "WOAH TOTAL FAILURE", book
开发者ID:azizmb,项目名称:whatrur,代码行数:35,代码来源:update_books.py

示例7: insert_action

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def insert_action(request):
    #try:

    inputed_isbn = request.POST['br-input-isbn']
    inputed_bcover = request.POST['br-input-bcover']
    inputed_bname = request.POST['br-input-bname']
    inputed_author = request.POST['br-input-author']
    inputed_translator = request.POST['br-input-translator']
    inputed_publisher = request.POST['br-input-publisher']
    inputed_byear = request.POST['br-input-byear']
    inputed_pagination = request.POST['br-input-pagination']
    inputed_price = request.POST['br-input-price']
    inputed_insertednum = request.POST['br-input-insertednum']

    try:
        book=Book.objects.get(isbn=inputed_isbn)

        book.bname=B(inputed_bname)
        book.author=B(inputed_author)
        book.translator=B(inputed_translator)
        book.byear=B(inputed_byear)
        book.pagination=int(inputed_pagination)
        book.price=float(inputed_price)
        # TODO : 封面应该下载到本地储存或SAE storage
        book.bcover=B(inputed_bcover)
        book.publisher=B(inputed_publisher)
        book.totalnum=book.totalnum+int(inputed_insertednum)
        book.available=book.available+int(inputed_insertednum)

        book.save()

        return HttpResponseRedirect("/success/insert")

    except Book.DoesNotExist:
        book=Book(
            isbn=B(inputed_isbn),
            bname=B(inputed_bname),
            author=B(inputed_author),
            translator=B(inputed_translator),
            byear=B(inputed_byear),
            pagination = 0,
            price=float(inputed_price),
            # TODO : 封面应该下载到本地储存或SAE storage
            bcover=B(inputed_bcover),
            publisher=B(inputed_publisher),
            totalnum=int(inputed_insertednum),
            available=int(inputed_insertednum),
            )
        if(inputed_pagination!=''):
            book.pagination=int(inputed_pagination)

        book.save()
        return HttpResponseRedirect("/success/insert")
    except Book.MultipleObjectsReturned as e: #isbn不唯一
        #TODO:其实这里新建一条记录可能比较好
        raise Exception(Book.STATIC_BOOKS_WITH_SAME_ISBN+unicode(e))
    """
开发者ID:DengZuoheng,项目名称:lib.eic.su,代码行数:59,代码来源:actions.py

示例8: dispatch_request

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
 def dispatch_request(self):
     form = BookForm()
     form.authors.query = Author.query.all()
     if request.method == "POST":
         if form.validate_on_submit():
             obj = Book()
             form.populate_obj(obj)
             obj.save()
             return redirect("/books/")
     return render_template("book_add.html", form=form)
开发者ID:bilunyk,项目名称:elibrary,代码行数:12,代码来源:views.py

示例9: save

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def save(request):
    form = BookForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        new_book = Book(isbn=cd['isbn'],
                        title=cd['title'],
                        author=cd['author'],
                        cover=cd['cover'])
    new_book.save()
    return HttpResponseRedirect('/')
开发者ID:epkatz,项目名称:nechama,代码行数:12,代码来源:views.py

示例10: test_book_autodelete

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
 def test_book_autodelete(self):
     note1 = Note(text='text')
     note1.save()
     note2 = Note(text='text')
     note2.save()
     book = Book(title='title')
     book.save()
     book.notes.add(*[note1, note2])
     note1.delete()
     self.assertTrue(Book.objects.all())
     note2.delete()
     self.assertFalse(Book.objects.all())
开发者ID:gowa66,项目名称:Andrey_Gorshunow_test_livarava,代码行数:14,代码来源:tests.py

示例11: new_book

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def new_book(request):
     t = get_template('feedback.html')
     try:

        author = Author.objects.get(name = request.GET['author'])
        date = request.GET['year']+'-'+request.GET['month']+'-'+request.GET['day']
        book = Book(title=request.GET['title'], author_id = author, publisher=request.GET['publisher'],
                    publish_date=date, price=request.GET['price'])
        book.save()
        html = t.render(Context({'text':'操作成功'}))
     except:
         html = t.render(Context({'text':'操作失败'}))
     return HttpResponse(html)
开发者ID:Polaris1123322,项目名称:lab4,代码行数:15,代码来源:views.py

示例12: submit

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def submit(request):
    if request.POST:    
        post = request.POST
        p=Author.objects.get(AuthorID =post["authorid"])
        new_book = Book(
            Title = post["title"],
            ISBN = post["isbn"],
            Publisher = post["pub"],
            PublishDate = post["date"],
            Price = post["price"],
            Authors=p)
        new_book.save()
        return  HttpResponseRedirect('/home/') 
开发者ID:DDawnlight,项目名称:commit,代码行数:15,代码来源:views.py

示例13: donate

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def donate(request):
    authenticated = False
    donated = False
    user_admin = False
    if request.user.is_superuser and request.user.is_staff:
        user_admin = True
    if request.user.is_authenticated():
        authenticated = True

    donations = Donate.objects.values()
    form = DonateForm(request.POST or None, request.FILES or None)
    if request.method == 'POST':
        smth = True
        for donation in donations:
            if 'accept' + str(donation['id_donate']) in request.POST:
                book = Book(ISBN=donation['ISBN'],
                            title=donation['title'],
                            author=donation['author'],
                            genre=donation['genre'],
                            image=donation['image']
                            )
                book.save()
                Donate.objects.filter(id_donate=donation['id_donate']).delete()
                email_user(user=request.user,
                           subject='donate book',
                           message='Your book donation for' + donation.title + ' has been accepted')
                smth = False
                break
            if 'reject' + str(donation['id_donate']) in request.POST:
                Donate.objects.filter(id_donate=donation['id_donate']).delete()
                smth = False
                email_user(user=request.user,
                           subject='donate book',
                           message='Your book donation for' + donation.title + ' has been declined')
                break
        if smth and form.is_valid():
            donation = form.save(commit=False)
            donation.user = request.user
            donation.image = form.cleaned_data['simage']
            donation.save()
            donated = True
            email_user(user=request.user,
                       subject='donate book',
                       message='Request for donating ' + donation.title + " received")
    donations = Donate.objects.values()

    return render_to_response("book_donate.html", context_instance=RequestContext(request,
                                                                                  {'authenticated': authenticated,
                                                                                   'user_admin': user_admin,
                                                                                   'donations': donations, 'form': form,
                                                                                   'donated': donated}))
开发者ID:jangau,项目名称:online_library,代码行数:53,代码来源:views.py

示例14: add

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def add(request):
#    return render_to_response('add.html',)  
     if request.POST:
        name = request.POST
        form= Book(   ISBN = name["ISBN"],
                      Title = name["Title"],
                      AuthorID = List_Au[0],
                      Publisher = name["Publisher"],
                      PublishDate = name["PublishDate"],
                      Price = name["Price"],
                                )       
        form.save()
        return HttpResponseRedirect(reverse("BookDB_list"))
     return render_to_response('add.html', {'form': AddForm()})
开发者ID:NeroJ,项目名称:lab4-2,代码行数:16,代码来源:views.py

示例15: groupTask

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import save [as 别名]
def groupTask(index):
    single_obj = Book()
    url_template = "http://category.dangdang.com/pg%d-cp01.00.00.00.00.00.html"
    handle = Handle(url_template % index)
    urls = handle.getValue()
    for element in urls:
        book = SingleBook(element)
        result = book.getValue()
        try:
            single_obj.insert(result)
            single_obj.save()
            print "book: %s" % result["book_name"]
        except Exception as error:
            print "fail one"
开发者ID:ClaudeXin,项目名称:SanLianManagement,代码行数:16,代码来源:obtain.py


注:本文中的models.Book.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。