Exemplo n.º 1
0
def add_category():
    py = Category("Python")
    p = Post("hello python!", "python is pretty cool ", py)
    py.save()
    p.save()

    return "add category success"
Exemplo n.º 2
0
def fenlei_xinwen_fabu(request):
    if request.session.get('username'):
        categories = Category.objects.all()
        if request.method == 'POST':
            category = request.POST.get('category')
            for cate in categories:
                if category == cate.c_name:
                    messages.add_message(request,
                                         messages.ERROR,
                                         '分类重复',
                                         extra_tags='alert alert-danger')
                    return render(request, 'fenlei_xinwen_fabu.html', locals())
            else:
                cate = Category(c_name=category)
                cate.save()
                return redirect(reverse('App:left_cate'))
    else:
        return redirect(reverse('App:login'))
    return render(request, 'fenlei_xinwen_fabu.html', locals())
Exemplo n.º 3
0
def pub_category(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST)
        if form.is_valid():
            name = request.POST.get('name')
            num = request.POST.get('num')
            categories = Category.objects.all()
            # print(categories)
            for data in categories:
                if data.name == name:
                    messages.error(request, '该类别已存在,请重新输入')
                    return render(request, 'category_fabu.html')
            else:
                category = Category(name=name, num=num)
                category.save()
                return redirect(reverse('App03:catg'))
        else:
            return render(request, 'category_fabu.html', locals())
    else:
        return render(request, 'category_fabu.html')