Beispiel #1
0
 def add_cat(self):
     name = str(self.add_cat_field.text())
     if name:
         new_cat = Category(name=name)
         new_cat.save()
         self.table.update()
         self.add_cat_field.setText("")
Beispiel #2
0
def menuEdit(request):
    if request.method == 'POST':
        if 'delItem' in request.POST:
	  print request.POST
	  MenuItem.objects.filter(name=request.POST['delItem']).delete()
	  return HttpResponseRedirect(".")
	elif 'addItem' in request.POST:
	  try:
	      priceVal = int(request.POST['price'])
	      pPriceVal = int(request.POST['pPrice'])
	      catId = int(request.POST['cat'])
	  except ValueError:
	      return HttpResponseRedirect(".")
	  cat = Category.objects.filter(id=catId)[0]
	  try:
	    item = MenuItem(name=request.POST['name'], price=priceVal, pPrice=pPriceVal, category=cat)
	    item.save()
	  except IntegrityError:
	    return HttpResponseRedirect(".")
	elif 'addCat' in request.POST:
	  try:
	    cat = Category(name=request.POST['cat'])
	    cat.save()
	  except IntegrityError:
	    return HttpResponseRedirect(".")
	elif 'delCat' in request.POST:
	  cat = Category.objects.filter(name=request.POST['delCat'])
	  print cat
	  print MenuItem.objects.filter(category=cat)
	  MenuItem.objects.filter(category=cat).delete()
	  cat.delete()
	  return HttpResponseRedirect(".")
    itemDict = {}
    cats = Category.objects.all().order_by("name")
    for c in cats:
        cItems = MenuItem.objects.filter(category=c).order_by("name")
        itemDict[c] = cItems
    return render_to_response("pmenu_list_edit.html", { "itemDict":itemDict})