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


Python Article.pub_date方法代码示例

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


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

示例1: dealWithArticle

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import pub_date [as 别名]
def dealWithArticle(request, post_id=0):
	'''
	если post_id = 0 => аргумент был не передан и мы создаем статью
	иначе редактируем статью с id = post_id
	надо будет прикрутить куки, чтобы... после редактирования статьи возвращать
	на страницу, откуда статья редактировалась.
	а после создания статьи возвращать страницу новосозданной статьи
	'''
	if post_id == 0:
		#добавление статьи
		mode = 0
	else:
		#редактирование статьи
		mode = 1
	try:
		article = Article.objects.get(pk = post_id)
		article_form = ArticleForm(instance = article)
		article = article_form.save(commit = False)
	except Article.DoesNotExist:
		article = Article()
		
		
	if request.POST:
		post = request.POST.copy()
		new_article_form = ArticleForm(post)
		if new_article_form.is_valid():
			new_article = new_article_form.save(commit = False)
			
			article.title = new_article.title
			article.bb_text = new_article.bb_text
			article.main_text = render_bbcode(new_article.bb_text)
			article.desc_text = render_bbcode(get_desc(new_article.bb_text))
			article.pub_date = timezone.now()
			article.is_big = is_big(article.main_text)
			
			article.save()
			return HttpResponseRedirect(reverse('blog.views.post',kwargs={'post_id':article.id}))
		else:
			return render_to_response('article_form.html',{'article_form': new_article_form, 
														   'mode':mode,
														   'url_ref': ref_for_article_form},
															context_instance=RequestContext(request))
	else:
		#добавляем статью
		if mode == 0:
			article_form = ArticleForm()
			return render_to_response('article_form.html',{'article_form': article_form,
													   'mode':mode,
													   'url_ref': ref_for_article_form},
														context_instance=RequestContext(request))
		if mode == 1:
			return render_to_response('article_form.html',{'article_form': article_form,
														   'mode':mode,
														   'url_ref': ref_for_article_form,
														   'article_id':article.id},
															context_instance=RequestContext(request))
开发者ID:ShadowOfManul,项目名称:testing-blog,代码行数:58,代码来源:views.py


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