def run(): from forum.models import Category forum_category_1 = Category() forum_category_1.name = u'Radio' forum_category_1.sort_order = 0 forum_category_1.save() from forum.models import Forum forum_forum_1 = Forum() forum_forum_1.title = u'Radio forum' forum_forum_1.slug = u'radio-forum' forum_forum_1.parent = None forum_forum_1.description = u'Stuff about the radio.' forum_forum_1.threads = 0 forum_forum_1.posts = 0 forum_forum_1.category = forum_category_1 forum_forum_1.anonymous = False forum_forum_1.sort_order = 0 forum_forum_1.save() from forum.models import Thread from forum.models import Post from forum.models import Subscription from forum.models import LastRead
def new_forum(request): form = ForumForm() if request.method == 'POST': form = ForumForm(request.POST) if form.is_valid(): forum = Forum() forum.title = form.cleaned_data['title'] forum.description = form.cleaned_data['description'] forum.creator = request.user forum.save() return HttpResponseRedirect(reverse('forum:forum-index')) return render( request, 'forum/new-forum.html', {'form': form}, )
def add_forum(request): ''' 新增帖子 :param request: :return: ''' category = Forum_plate.objects.all() if request.method == 'POST': form = Forum_form(request.POST) if form.is_valid(): forum = Forum() forum.title = form.cleaned_data.get('title') forum.category_id = form.cleaned_data.get('category') forum.keywords = form.cleaned_data.get('keywords') forum.content = form.cleaned_data.get('content') forum.authors = form.cleaned_data.get('authors') try: forum.save() return JsonResponse({"code": 200, "data": "发布成功"}) except Exception: return JsonResponse({"code": 400, "data": "发布失败"}) return JsonResponse({"code": 400, "data": "发布失败"}) return render(request, 'pc/forum_add.html', locals())