本文整理汇总了Python中blog.models.Blog.author方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.author方法的具体用法?Python Blog.author怎么用?Python Blog.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Blog
的用法示例。
在下文中一共展示了Blog.author方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_valid
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import author [as 别名]
def form_valid(self, form):
if hasattr(self.request.user, 'blog'):
form.instance.blog = self.request.user.blog
else:
if 'create' in self.request.POST:
blog = Blog()
blog.author = self.request.user
blog.title = self.request.user.get_full_name()
blog.save()
form.instance.blog = blog
return super(PostCreateView, self).form_valid(form)
示例2: create_blog
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import author [as 别名]
def create_blog(request):
if request.method == 'POST':
items = request.POST
if not items['title'] or not items['slug'] or not items['body']:
messages.error(request, 'Title, Slug, Body are required fields.')
return redirect('create_blog')
b = Blog(title=items['title'], slug=items['slug'], body=str(items['body']))
if 'gtoken' in request.COOKIES:
gitkit_user = gitkit.VerifyGitkitToken(request.COOKIES['gtoken'])
if gitkit_user:
b.author = gitkit_user.email
if get_uploads(request, 'image') and request.FILES.get('image'):
blob_key = get_uploads(request, 'image')[0].key()
b.blob_key = blob_key
b.put()
return HttpResponseRedirect('/')
else:
return render(request, 'blog/create_blog.html', {'upload_url': blobstore.create_upload_url(success_path='/create_blog')})