新增分类
(pid int, cates string)
| 39 | |
| 40 | //新增分类 |
| 41 | func (this *Category) AddCates(pid int, cates string) (err error) { |
| 42 | slice := strings.Split(cates, "\n") |
| 43 | if len(slice) == 0 { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | o := orm.NewOrm() |
| 48 | for _, item := range slice { |
| 49 | if item = strings.TrimSpace(item); item != "" { |
| 50 | var cate = Category{ |
| 51 | Pid: pid, |
| 52 | Title: item, |
| 53 | Status: true, |
| 54 | } |
| 55 | if cnt, _ := o.QueryTable(this).Filter("title", cate.Title).Filter("pid", cate.Pid).Count(); cnt == 0 { |
| 56 | _, err = orm.NewOrm().Insert(&cate) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | //删除分类(如果分类下的书籍不为0,则不允许删除) |
| 64 | func (this *Category) Del(id int) (err error) { |