def post(self, request): form = CategoryForm(data=request.POST) if form.is_valid(): form.save() return redirect('manager:categoryControl') else: return HttpResponse('Sai Cu Phap')
def post(self, request): form = CategoryForm(request.POST) if form.is_valid(): form.save() return redirect('/manager/') else: return HttpResponse("Sai cu phap")
def post(request, category_id): form = CategoryForm(request.POST) if form.errors: messages.add_message(request, messages.INFO, dict(form.errors.items())) if form.is_valid(): try: ProductCategory.edit_category( category_id, { 'name': form.cleaned_data.get('name'), }) return HttpResponseRedirect('/admin/categories') except: pass category = ProductCategory.get_by_id(category_id) return TemplateResponse( request, 'category.html', { 'category': category, 'form_data': form.cleaned_data, 'error_messages': get_error_message(request), })
def category(request): form = CategoryForm(request.POST or None) if form.is_valid(): cat = form.save() return redirect('category') categories = Category.objects.all() context = {'categories': categories, 'form': form} return render(request, 'dashboard/category.html', context)
def add_category(request): if request.method == "POST": form = CategoryForm(request.POST, request.FILES) if form.is_valid(): form.save() messages.success(request, "Catogery added successfully") return redirect('admin_products') else: messages.error(request, "Bad Data or Already Exit") return redirect('admin_products') return render(request, 'admin/products.html')
def get(self, request, action_id): if action_id == 1: product = ProductForm() return render(request, "store/manage_Action.html", {"add_product": product}) if action_id == 2: category = CategoryForm() return render(request, "store/manage_Action.html", {"add_category": category})
def post(self, request, action_id): if action_id == 1: form = ProductForm(data=request.POST, files=request.FILES) if action_id == 2: form = CategoryForm(request.POST) if form.is_valid(): form.save() return redirect('http://127.0.0.1:8000/manage/') else: return HttpResponse("Sai cu phap")
def post(self, request, *args, **kwargs): some_var = request.POST.getlist('product') products = Product.objects.all() form = ProductsForm(request.POST or None, request.FILES or None) form_category = CategoryForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.save() return redirect('manager-products') if form_category.is_valid(): form_category.save() return redirect('manager-products') for item in some_var: instance = Product.objects.get(id=item) instance.delete() return render(request, self.template_name, context={ 'products': products, 'form': form, 'form_category': form_category, })
def product_list(request): object_list = Item.objects.all() form = ItemForm() form_category = CategoryForm() categories = Category.objects.all() if 'product' in request.GET: product_name = request.GET['product'] if product_name: object_list = Item.objects.filter(title__iexact=product_name) return render( request, 'admin/products.html', { 'object_list': object_list, 'categories': categories, 'form': form, 'form_category': form_category })
def get(self, request, *args, **kwargs): history = LogEntry.objects.all() search_query = request.GET.get('search', None) page = request.GET.get('page', 1) min_price = request.GET.get('min_price', None) max_price = request.GET.get('max_price', None) min_quantity = request.GET.get('min_quantity', None) max_quantity = request.GET.get('max_quantity', None) category = request.GET.get('category', None) products = Product.objects.all() categories = Category.objects.all() form = ProductsForm() form_category = CategoryForm() if search_query: products = products.filter( Q(name__icontains=search_query) | Q(barcode__icontains=search_query) | Q(id__icontains=search_query)) if category: products = products.filter(categories_name__name=category) if min_price: products = products.filter(selling_price__gte=float(min_price)) if max_price: products = products.filter(selling_price__lte=float(max_price)) if min_quantity: products = products.filter(quantity__gte=int(min_quantity)) if max_quantity: products = products.filter(quantity__lte=int(max_quantity)) paginator = Paginator(products, self.products_per_page) result = paginator.get_page(page) return render(request, self.template_name, context={ 'products': result, 'categories': categories, 'history': history, 'form': form, 'form_category': form_category, })
def get(self, request): form = CategoryForm() context = {"form": form} return render(request, 'manager/categoryControl/AddCategory.html', context)
def get(self, request): category = CategoryForm() return render(request, "manager/manage_Action.html", {"add_category": category})
def addProductCategory(request): context = {} if request.method == 'POST': login_data = request.POST.dict() print(login_data) if request.session.get('userId') is not None: userId = int(request.session['userId']) try: user = getUser(userId) productClass = ProductClass.objects.get(id=int(login_data['productClass'])) # productClass = ProductClass.objects.get(id=3) print('1') with transaction.atomic(): productCategory = None isActive = '' if login_data['active']: isActive = True else: isActive = False print('3') if user != None: name = login_data['name'] description = login_data['description'] productCategory = ProductCategory( name=name, categoryDescription=description, productClass = productClass, isActive=isActive, createdBy=user ) productCategory.save() messages.success(request, INFO_CATEGORY_ADDITION_SUCCESS) listOfCategory = ProductCategory.objects.filter(createdBy=user).filter(isActive=True) context['listOfCategory'] = listOfCategory if 'save_display' in request.POST: print('Here') return render(request, 'product/listProductCategory.html', context) elif 'save_add' in request.POST: print('Here 1') form1 = CategoryForm(request.POST or None) context = { "form1": form1 } return render(request, 'product/addProductCategory.html', context) except Exception as ex: print(ex) messages.success(request, INFO_CATEGORY_ADDITION_FAILURE) form1 = CategoryForm(request.POST or None) context = { "form1": form1 } return render(request, 'product/addProductCategory.html', context) form1 = CategoryForm(request.POST or None) # form1 = CategoryForm() # if form1.is_valid(): # instance = form1.save(commit=False) # instance.save() context = { "form1": form1 } return render(request, 'product/addProductCategory.html', context)
def _create_category(request): form = CategoryForm(request.POST or None) if form.is_valid(): cat = form.save() return JsonResponse({'id': cat.id, 'name': cat.name}) return render(request, 'staff/create-form.html', {'form': form})