python大作业图书管理系统_django图书管理系统

【实例简介】图书管理系统

【实例截图】

【核心代码】from django.shortcuts import render, redirect, HttpResponse

from app01.models import *

from django.shortcuts import render,redirect,reverse

# Create your views here.

def add_book(request):

"""

添加书籍信息的视图函数

:param request:

:return:

"""

if request.POST:

title = request.POST.get("title")

price = request.POST.get("price")

date = request.POST.get("date")

publish = request.POST.get("publish")

authors = request.POST.getlist('authors')

book_obj = Book.objects.create(title=title, price=price, pub_date=date, publish_id=publish)

book_obj.authors.add(*authors)

return redirect('app01:books')

pub_list = Publish.objects.all()

aut_list = Author.objects.all()

return render(request, 'add_book.html', {'pub_list': pub_list, 'aut_list': aut_list})

def mod_book(request, id):

mod_obj = Book.objects.filter(nid=id).first()

if request.POST:

title = request.POST.get("title")

price = request.POST.get("price")

date = request.POST.get("date")

publish = request.POST.get("publish")

authors = request.POST.getlist('authors')

Book.objects.filter(pk=id).update(title=title, price=price, pub_date=date, publish_id=publish)

mod_obj.authors.set(authors)

return redirect('app01:books')

pub_list = Publish.objects.all()

aut_list = Author.objects.all()

return render(request, 'modbook.html', {'mod_obj': mod_obj, 'pub_list': pub_list, 'aut_list': aut_list})

def books(request):

book_list = Book.objects.all()

return render(request, 'books.html', {'book_list': book_list})

def del_book(request, id):

Book.objects.filter(nid=id).delete()

return redirect('app01:books')

def aut_detail(request, id, tag):

if tag == "2":

print(id)

book_list = Book.objects.filter(authors__nid=id).all()

else:

book_list = Book.objects.filter(publish_id=id).all()

return render(request, 'book_detail.html', locals())

def index(request):

return HttpResponse("shouye")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值