def post(self, request): form = WriteNewsForm(request.POST) if form.is_valid(): title = form.cleaned_data.get('title') desc = form.cleaned_data.get('desc') thumbnail = form.cleaned_data.get('thumbnail') content = form.cleaned_data.get('content') category_id = form.cleaned_data.get('category') category = NewCategory.objects.get(pk=category_id) News.objects.create(title=title, desc=desc, thumbnail=thumbnail, content=content, category=category, author=request.user) return Response.response() else: return Response.params_error(message=form.get_errors())
def post(self, request): form = WriteNewsForm(request.POST) if form.is_valid(): title = form.cleaned_data.get("title") desc = form.cleaned_data.get("desc") thumbnail = form.cleaned_data.get("thumbnail") content = form.cleaned_data.get("content") category_id = form.cleaned_data.get("category") category = NewsCategory.objects.get(pk=category_id) News.objects.create(title=title, desc=desc, thumbnail=thumbnail, content=content, category=category, author=request.user) return restful.ok() else: return restful.params_error(message=form.get_errors())
def post(self): form = WriteNewsForm() if form.is_valid(): #文章分类接收过来的是一个id #根据id 获取这个分类对象 pass