コード例 #1
0
ファイル: dummy_data.py プロジェクト: kovoli/cbv_dj_doc
def book_dummy(n):
    for _ in range(n):
        a = Author.objects.all()
        author = random.choice(a)
        p = Publisher.objects.all()
        publi = random.choice(p)

        book = Book(title=fake.text(),
                    publisher=publi,
                    publication_date=fake.date())
        book.save()
        book.authors.add(author)
コード例 #2
0
def add(req):
    author1 = Author.objects.create(name="作者3")
    author2 = Author.objects.create(name="作者4")

    book = Book()
    book.name = "Thinging In Java"
    book.save()
    book.authors.add(author1)
    book.authors.add(author2)

    # book1 = Book.objects.create(name="Thinging In Java", author=author1)
    # book2 = Book.objects.create(name="30精通Python", authors=[author1, author2])
    # book3 = Book.objects.create(name="精通HTML", author=author2)
    # book4 = Book.objects.create(name="精通Nodejs", author=author2)

    return HttpResponse("<h3>添加成功</h3>")
コード例 #3
0
ファイル: views2.py プロジェクト: tzq668766/django_train
def add(req):
    author1 = Author.objects.create(name="作者3")
    author2 = Author.objects.create(name="作者4")

    book = Book()
    book.name = "Thinging In Java"
    book.save()
    book.authors.add(author1)
    book.authors.add(author2)

    # book1 = Book.objects.create(name="Thinging In Java", author=author1)
   # book2 = Book.objects.create(name="30精通Python", authors=[author1, author2])
    # book3 = Book.objects.create(name="精通HTML", author=author2)
    # book4 = Book.objects.create(name="精通Nodejs", author=author2)

    return HttpResponse("<h3>添加成功</h3>")
コード例 #4
0
ファイル: fakes.py プロジェクト: sallyyou/blog
def fake_books(count=50):
    for i in range(count):
        book = Book(name=fake.sentence(),
                    comment=fake.text(2000),
                    category=BookCategory.query.get(
                        random.randint(1, BookCategory.query.count())),
                    timestamp=fake.date_time_this_year())

        db.session.add(book)
    db.session.commit()
コード例 #5
0
ファイル: views.py プロジェクト: xishouweb/NyBlog
def sharefile(request):
    login_value = get_login_value(request)
    if login_value['state'] == 2:
        return HttpResponseRedirect("../home")
    if request.method == 'POST':
        form = ShareFileForm(request.POST)
        if form.is_valid():
            book = Book()
            book.title = form.cleaned_data['title']
            book.category = form.cleaned_data['category']
            book.imgurl = form.cleaned_data['imgurl']
            book.introduction = form.cleaned_data['introduction']
            book.downloadurl = form.cleaned_data['downloadurl']
            book.save()
            return HttpResponseRedirect("../user")
    else:
        form = ShareFileForm()
    return render(request, 'sharefile.html',
                  {'form': form, 'tools': get_tools(), 'name': login_value['name'], 'url': login_value['url'],
                   'class': login_value['class_value'], 'num': login_value['state']})
コード例 #6
0
def AddBook():
    categories=Category.query.all()
    form=BookForm()
    if form.validate_on_submit():
        name=form.name.data
        page=form.page.data
        price=form.price.data
        much=form.much.data
        jold=form.jold.data
        desc=form.desc.data
        category=request.form.get('category')
        image1=photos.save(request.files.get('image1'),name=secrets.token_hex(10)+".")
        add=Book(name=name,page=page,price=price,much=much,jold=jold,desc=desc,image1=image1,category_id=category)
        db.session.add(add)
        db.session.commit()
        flash(f'Product Created Successfully','success')
        return redirect(url_for('index'))
    return render_template('addbook.html',form=form,categories=categories)
コード例 #7
0
ファイル: views.py プロジェクト: fakegit/NyBlog
def sharefile(request):
    logging_status = get_logging_status(request)
    if logging_status['login_state'] == BLOGSETTING.UNLOGGED:
        return HttpResponseRedirect("/home")
    if request.method == 'POST':
        form = ShareFileForm(request.POST)
        if form.is_valid():
            book = Book()
            book.title = form.cleaned_data['title']
            book.category = form.cleaned_data['category']
            book.imgurl = form.cleaned_data['imgurl']
            book.introduction = form.cleaned_data['introduction']
            book.downloadurl = form.cleaned_data['downloadurl']
            book.save()
            return HttpResponseRedirect("/user")
    else:
        form = ShareFileForm()
    return render(request, 'sharefile.html',
                  {'form': form,
                   'tools': get_tools(),
                   'username': logging_status['username'],
                   'userurl': logging_status['userurl'],
                   'btn_class_value': logging_status['btn_class_value'],
                   'login_state': logging_status['login_state'],})
コード例 #8
0
def create_book_normal(request):
    template_name = 'blog/create_normal.html'
    heading_message = 'Formset Demo'
    if request.method == 'GET':
        formset = BookFormset(request.GET or None)
    elif request.method == 'POST':
        formset = BookFormset(request.POST)
        if formset.is_valid():
            for form in formset:
                # extract name from each form and save
                name = form.cleaned_data.get('name')
                # save book instance
                if name:
                    Book(name=name).save()
            # once all books are saved, redirect to book list view
            return redirect('book_normal')
            #return redirect('book_list')
    return render(request, template_name, {
        'formset': formset,
        'heading': heading_message,
    })