Exemplo n.º 1
0
def add_cls(req):
    mess =[]
    form = clsF()
    if req.method=="POST":
        form = clsF(req.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            Cls.objects.create(name=name)
            mess.append('添加分类成功')
        else:
            mess.append('添加的数据不合法')
    return render(req,'add_class.html',{'form':form,'mess':mess,'loged':1})
Exemplo n.º 2
0
def add_tag(req):
    mess = []
    form = tagF()
    form2 = clsF()
    if req.method=="POST":
        form = tagF(req.POST)
        form2 =clsF(req.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            if not Tag.objects.all().filter(name=name):
                Tag.objects.create(name=name)
                mess.append("添加标签成功")
        else:
            if form2.is_valid():
                name = form.cleaned_data['name']
                Cls.objects.create(name=name)
                mess.append("添加分类成功")
            else:
                mess.append('添加的数据不合法')
    return render(req,'add_tag.html',{'form':form,'form2':form2,'mess':mess,'loged':1})