当前位置: 首页>>代码示例>>Python>>正文


Python News.media方法代码示例

本文整理汇总了Python中models.News.media方法的典型用法代码示例。如果您正苦于以下问题:Python News.media方法的具体用法?Python News.media怎么用?Python News.media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.News的用法示例。


在下文中一共展示了News.media方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_news

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import media [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/')
开发者ID:TorinAsakura,项目名称:gk,代码行数:55,代码来源:views.py


注:本文中的models.News.media方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。