def plants_delete(request): id = request.POST.get('id') data = models.PlantsInfo.plants.get(id=id) data.is_del = 1 data.delete_time = time.time() data.save() return common.success()
def flora_update(request): id = request.POST.get("id") introduction = request.POST.get("introduction", '') flora_name = request.POST.get("flora_name") data = models.FloraInfo.flora.get(id=id) data.flora_name = flora_name data.introduction = introduction data.update_time = time.time() data.save() return common.success()
def flora_delete(request): id = request.POST.get("id") #下面有未删除children,则无法删除 tmpData = models.FloraInfo.flora.filter(pid=id, is_del=0).values() if tmpData.exists(): return common.error('不能删除该分类') data = models.FloraInfo.flora.get(id=id) data.is_del = 1 data.delete_time = time.time() data.save() return common.success()
def plants_add(request): plant_name = request.POST.get('plant_name') flora_id = request.POST.get('flora_id') introduction = request.POST.get('introduction', '') photo = request.FILES.get('file') shooting_time = request.POST.get('shooting_time') plant = models.PlantsInfo(plant_name=plant_name, flora_id=flora_id, introduction=introduction, photo=photo, shooting_time=shooting_time) plant.save() return common.success()
def plants_info(request): id = request.POST.get('id') tmp_data = models.PlantsInfo.plants.get(id=id) # print('http://127.0.0.1:8000/media/img/'+str(tmp_data.photo)) data = {} data['id'] = tmp_data.id data['plant_name'] = tmp_data.plant_name data['flora_id'] = tmp_data.flora_id data['introduction'] = tmp_data.introduction data['photo'] = 'http://127.0.0.1:8000/media/' + str(tmp_data.photo) data['shooting_time'] = tmp_data.shooting_time return common.success(data)
def flora_add(request): pid = request.POST.get("pid") flora_name = request.POST.get("flora_name") introduction = request.POST.get("introduction", '') if pid == 0: pid_tree = '0' else: temp = models.FloraInfo.flora.get(id=pid) pid_tree = str(temp.pid_tree) + ':' + str(temp.id) # print(temp.pid_tree) flora = models.FloraInfo(pid=pid, flora_name=flora_name, introduction=introduction, pid_tree=pid_tree) flora.save() return common.success()
def plants_list(request): flora_id = request.POST.get('flora_id') page = request.POST.get('page', 1) limit = request.POST.get('limit', 20) total = models.PlantsInfo.plants.filter(is_del=0, flora_id=flora_id).count() data = common.paging(page, limit, total) ret = models.PlantsInfo.plants.filter( is_del=0, flora_id=flora_id).values()[data.get('offset'):data.get('offset') + data.get('size')] tmp_data = list(ret) data = {} data['list'] = tmp_data data['total'] = total return common.success(data)
def plants_update(request): id = request.POST.get('id') plant_name = request.POST.get('plant_name') flora_id = request.POST.get('flora_id') introduction = request.POST.get('introduction', '') photo = request.FILES.get('file', 0) shooting_time = request.POST.get('shooting_time') data = models.PlantsInfo.plants.get(id=id) data.plant_name = plant_name data.flora_id = flora_id data.introduction = introduction data.shooting_time = shooting_time if photo: data.photo = photo data.update_time = time.time() data.save() return common.success()
def flora_list(request): ret = models.FloraInfo.flora.filter(is_del=0).values() data = list(ret) return common.success(data)
def flora_info(request): id = request.POST.get("id", 0) ret = models.FloraInfo.flora.get(id=id) data = model_to_dict(ret) return common.success(data)