def add_book(request): response = {} try: book = Book(book_name=request.GET.get('book_name')) book.save() response['msg'] = 'success' response['error_num'] = 0 except Exception, e: response['msg'] = str(e) response['error_num'] = 1
def add_answer(request): response = {} try: book = Book(book_name=request.GET.get('book_name')) book.save() response['msg'] = 'success' response['error_num'] = 0 except Exception as e: response['msg'] = str(e) response['error_num'] = 1 return JsonResponse(response)
def test_two(self): print "Inside test_two" # Add another author on the fly author = Author() author.first_name = 'Aldous' author.last_name = 'Huxley' self.db.session.add(author) # Add another book for the new author book = Book() book.title = "Brave New World" book.published_date = datetime.datetime(1932, 5, 12) self.db.session.add(book) self.db.session.commit()
def test_one(self): print "Inside test_one" # Add another author on the fly author = Author() author.first_name = 'George' author.last_name = 'Orwell' self.db.session.add(author) # Add another book for the new author book = Book() book.title = "1984" book.published_date = datetime.datetime(1949, 6, 8) self.db.session.add(book) self.db.session.commit()
def add_book(): form = BookForm() books = Book.query.all() if form.validate_on_submit(): title = form.title.data author = form.author.data year = int(form.year.data) month = int(form.month.data) day = int(form.day.data) date_time = datetime.date(year, month, day) book = Book(title=title, author=author, publish_date=date_time) db.session.add(book) db.session.commit() return redirect(url_for('add_book')) return render_template('book.html', title="Kitap Ekle", form=form, books=books)
import json from myapp.models import Author, Book from bpmappers.djangomodel import ModelMapper class AuthorMapper(ModelMapper): class Meta: model = Author class BookMapper(ModelMapper): class Meta: model = Book author = Author(name="tokibito", company="BeProud") book = Book(title="Spam", price=500, author=author) # マッピングとJSON変換 print("author:", json.dumps(AuthorMapper(author).as_dict(), indent=2)) print("book:", json.dumps(BookMapper(book).as_dict(), indent=2))
def InsertBook(request, isbn, title, memo): Book(isbn=isbn, title=title, memo={'content': memo}).save() return render(request, 'myapp/mypage.html', { 'welcome_text': 'Insert: ' + title })