增删改查
增加
比较简单
查询
也简单
可以前段获取某个值在后台查询某个值
也可以用全文检索方式查询,不过这个方法方便是方便,需要配置的东西比较多
修改
class xiugai(View):
def get(self,request):
newsid = request.GET.get('id')
cate = Cate.objects.all()
newslist = News.objects.filter(id=newsid).first()
return render(request,'admin/xiu.html',{"cate":cate,"newslist":newslist})
def post(self,request):
newsid = request.GET.get('id')
print(newsid)
data = request.POST
title = data['title']
author =data['author']
cid =data['guishu']
image_url = request.FILES.get('file')
uploadfile(image_url)
rich_content =data['rich_content']
is_recommend=data['is_recommend']
upnew = News.objects.filter(id = newsid).first()
if newsid:
upnew.title = title
upnew.author = author
if image_url:
image_url='/upload/'+image_url.name
upnew.rich_content = rich_content
upnew.save()
return redirect('/sadmin/shownew')
删除
def del_new(request):
newsid = request.GET.get('id')
new = News.objects.filter(id=newsid).delete()
# new.save()
return redirect('/sadmin/shownew')