本文整理汇总了Python中blog.models.Blog.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.owner方法的具体用法?Python Blog.owner怎么用?Python Blog.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Blog
的用法示例。
在下文中一共展示了Blog.owner方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import owner [as 别名]
def post(self, request):
"""
Crea un user en base a la información POST
:param request: HttpRequest
:return: HttpResponse
"""
success_message = ''
form = SignupForm(request.POST)
if form.is_valid():
user = User()
user.username = form.cleaned_data.get('usr')
user.first_name = form.cleaned_data.get('first_name')
user.last_name = form.cleaned_data.get('last_name')
user.email = form.cleaned_data.get('email')
user.set_password(form.cleaned_data.get('password'))
user.save()
blog = Blog()
blog.title = "My first blog"
blog.owner = user
blog.save()
success_message = 'Creado con éxito!'
success_message += '<a href="{0}">'.format(
reverse('post_home', args=[])
)
success_message += 'go Home!'
success_message += '</a>'
context = {
'form': form,
'success_message': success_message
}
return render(request, 'users/new_user.html', context)
示例2: create_blog
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import owner [as 别名]
def create_blog(request):
errors = []
template = "blog/templates/create_blog.html"
form = CreateBlogForm()
user = request.user
if not user.is_authenticated():
raise Http404
if request.method == "POST":
form = CreateBlogForm(request.POST)
if form.is_valid():
try:
data = form.cleaned_data
_blog = Blog()
_blog.title = data["title"]
_blog.owner = user
_blog.url = data["url"]
_blog.tagline = data["tagline"]
_blog.active = True
_blog.save()
_blog.contributors.add(user)
_blog.save()
return HttpResponseRedirect("/blog/%s/"%user.username)
except:
errors.append("Blog URL already taken.")
return render(request, template, {"errors":errors, "form":form})
示例3: post
# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import owner [as 别名]
def post(self, request):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
new_user = serializer.save()
blog = Blog()
blog.title = request.data.get("blog")
blog.owner = new_user
blog.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)