From ec028bf23b149554698716ca62a60bd4488754d8 Mon Sep 17 00:00:00 2001 From: xieshen <1397910458@qq.com> Date: Wed, 21 Oct 2020 11:42:46 +0800 Subject: [PATCH] =?UTF-8?q?#=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/news-management-update.html | 144 ++++++++++++++++++ .../templates/management/news-management.html | 8 +- management/urls.py | 1 + management/views.py | 45 ++++++ 4 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 management/templates/management/news-management-update.html diff --git a/management/templates/management/news-management-update.html b/management/templates/management/news-management-update.html new file mode 100644 index 0000000..ecab1d7 --- /dev/null +++ b/management/templates/management/news-management-update.html @@ -0,0 +1,144 @@ +{% extends 'dashboard/base/base.html' %} +{% load static %} +{% block title %}祁连山生态监测数据管理平台{% endblock %} +{% block css %} + + + + + + + +{% endblock %} + +{% block content %} +
+ {% include 'dashboard/base/left.html' %} +
+
+ + {% if messages %} + + + {% endif %} + +
+

编辑新闻

+
+ + +
{% csrf_token %} +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ {{ news.date }} + +
+
+ + +
+
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+
+
+
+{% endblock %} + + +{% block add_js %} + + + + + + + + {# #} + {# #} + {# #} + {##} + {##} + {# #} +{% endblock %} diff --git a/management/templates/management/news-management.html b/management/templates/management/news-management.html index 16cca3d..1d36081 100644 --- a/management/templates/management/news-management.html +++ b/management/templates/management/news-management.html @@ -69,13 +69,15 @@ {% for n in news %} {{ forloop.counter }} - {{ n.title }} + {{ n.title }} {{ n.author }} {{ n.type }} {{ n.date }} - 查看 +{# 查看#} + 编辑 删除 diff --git a/management/urls.py b/management/urls.py index dbd0231..22e1f6d 100644 --- a/management/urls.py +++ b/management/urls.py @@ -55,6 +55,7 @@ urlpatterns = [ #新闻管理 path('news/management/',views.new_management,name='news-management'), path('news/management/create/', views.news_management_create, name='news-management-create'), + path('news/management/updaye//', views.news_management_update, name='news-management-update'), path('news/management/detail//', views.news_management_detail, name='news-management-detail'), path('news/management/delete//', views.news_management_delete, name='news-management-delete'), ] diff --git a/management/views.py b/management/views.py index 698276e..59c6044 100644 --- a/management/views.py +++ b/management/views.py @@ -1662,7 +1662,52 @@ def news_management_create(request): o['choices'] = list(i)[1] results.append(o) return render(request, 'management/news-management-create.html', {'type': results}) +@login_required +def news_management_update(request,pk): + news = News.objects.get(id=pk) + type = News.NEWMEDIA_NEWS_CHOICES + results = [] + for i in type: + o = dict() + o['choices'] = list(i)[1] + results.append(o) + if request.method == 'POST': + type = request.POST.get('type') + title = request.POST.get('title') + author = request.POST.get('author') + content = request.POST.get('content') + source = request.POST.get('source') + + t = None + if type == '政策依据': + t = '0' + elif type == "基层动态": + t = '1' + elif type == '外省动态': + t = '2' + elif type == '监测通报': + t = '3' + elif type == '舆情热点': + t = '4' + elif type == '通知': + t = '5' + elif type == '重点新闻': + t = '6' + if request.FILES.get('image'): + image = request.FILES.get('image') + if request.POST.get('date'): + date = request.POST.get('date') + News.objects.filter(id=pk).update(type=t, title=title, author=author, date=date, content=content, source=source, image=image) + else: + News.objects.filter(id=pk).update(type=t, title=title, author=author, content=content, + source=source, image=image) + else: + News.objects.filter(id=pk).update(type=t, title=title, author=author, content=content, + source=source) + messages.success(request,'编辑成功') + return HttpResponseRedirect('/management/news/management/') + return render(request,'management/news-management-update.html',{'news':news,'type':results}) @login_required def news_management_detail(request, pk):