本文整理匯總了Python中models.News.text方法的典型用法代碼示例。如果您正苦於以下問題:Python News.text方法的具體用法?Python News.text怎麽用?Python News.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.News
的用法示例。
在下文中一共展示了News.text方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_news
# 需要導入模塊: from models import News [as 別名]
# 或者: from models.News import text [as 別名]
def add_news(request):
imgroot = '/var/pj/gk/st/news/'
imgroot54x54 = '/var/pj/gk/st/news/54x54/'
if request.method == "POST":
title = request.POST['news_name']
tags = request.POST['news_tags']
active = request.POST['news_status']
category = request.POST['news_category']
sweight = request.POST['news_priority']
date = request.POST['news_date']
text = request.POST['news_content']
n = News()
if 'news_autor' in request.POST:
n.autor = request.POST['news_autor']
if 'news_photo_autor' in request.POST:
n.photo_title = request.POST['news_photo_autor']
if 'news_origin' in request.POST:
n.origin = request.POST['news_origin']
if 'news_city' in request.POST:
n.city = request.POST['news_city']
if 'news_media' in request.POST:
n.media = request.POST['news_media']
user = User.objects.get(username=request.user)
n.owner = user
n.title = title
if active == 'on':
active = True
else:
active = False
n.active = active
n.text = text
n.sweight = sweight
n.date = date
n.save()
tagsl = tags.split(',')
tagsitems = []
for item in tagsl:
if len(item.strip()):
tagsitems.append(Tag.objects.get_or_create(name=item.strip())[0].id)
n.tags = tagsitems
categoryl = category.split(',')
categoryitems = []
for item in categoryl:
if len(item.strip()):
categoryitems.append(item)
n.category = categoryitems
tmpfile = handle_uploaded_file(request.FILES['news_logo'], str(n.id) + request.FILES['news_logo'].name[-4:])
img = Image.open('/tmp/' + tmpfile)
img.save(imgroot + str(n.id) + '.png', 'PNG')
img.thumbnail([54, 54], Image.ANTIALIAS)
img.save(imgroot54x54 + str(n.id) + '.png', 'PNG')
request.session['alert'] = 'Новость успешно добавлена'
return redirect('/news/admin/')