def post(self, request): category_form = ProductCategoryEditForm(request.POST) if category_form.is_valid(): category_form.save() return HttpResponseRedirect(reverse('adminapp:categories')) else: return render(request, 'adminapp/user_update.html', {'update_form': category_form})
def post(self, request, **kwargs): edit_category = get_object_or_404(ProductCategory, pk=kwargs['pk']) category_form = ProductCategoryEditForm(request.POST, instance=edit_category) if category_form.is_valid(): category_form.save() return HttpResponseRedirect(reverse('adminapp:categories')) else: return render(request, 'adminapp/user_update.html', {'update_form': category_form})
def productcategory_create(request): if request.method == 'POST': form = ProductCategoryEditForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('myadmin:categories')) else: form = ProductCategoryEditForm() context = {'title': 'категории/создание', 'form': form} return render(request, 'adminapp/productcategory_form.html', context)
def category_create(request): if request.method == 'POST': category_form = ProductCategoryEditForm(request.POST, request.FILES) if category_form.is_valid(): category_form.save() return HttpResponseRedirect(reverse('admin:category_read')) else: category_form = ProductCategoryEditForm() content = {'form': category_form} return render(request, 'adminapp/category_create.html', content)
def category_create(request): title = 'категории/создание' if request.method == 'POST': category_form = ProductCategoryEditForm(request.POST, request.FILES) if category_form.is_valid(): category_form.save() return HttpResponseRedirect(reverse('admin:categories')) else: category_form = ProductCategoryEditForm() content = {'title': title, 'update_form': category_form} return render(request, 'adminapp/category_update.html', content)
def productcategory_update(request, pk): current_object = get_object_or_404(CardCategory, pk=pk) if request.method == 'POST': form = ProductCategoryEditForm(request.POST, request.FILES, instance=current_object) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('myadmin:categories')) else: form = ProductCategoryEditForm(instance=current_object) context = {'title': 'категории/редактирование', 'form': form} return render(request, 'adminapp/productcategory_update.html', context)
def category_create(request): title = "категории/создание" if request.method == "POST": category_form = ProductCategoryEditForm(request.POST, request.FILES) if category_form.is_valid(): category_form.save() return HttpResponseRedirect(reverse("admin:categories")) else: category_form = ProductCategoryEditForm() content = {"title": title, "update_form": category_form, "media_url": settings.MEDIA_URL} return render(request, "adminapp/category_update.html", content)
def admin_categories_update(request, category_id): current_category = ProductCategory.objects.get(id=category_id) if request.method == 'POST': form = ProductCategoryEditForm(data=request.POST, instance=current_category) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('admin_staff:admin_categories_read')) else: form = ProductCategoryEditForm(instance=current_category) context = {'form': form, 'current_category': current_category, } return render(request, 'adminapp/admin-categories-update-delete.html', context)
def categories_item_create(request): if request.method == 'POST': form = ProductCategoryEditForm(data=request.POST) if form.is_valid(): form.save() messages.success(request, 'Категория успешно создана!') return HttpResponseRedirect(reverse('admin_staff:categories')) else: messages.warning(request, form.errors) else: form = ProductCategoryEditForm() context = { 'form': form, } return render(request, 'adminapp/categories-item-create.html', context)
def category_update(request, pk): title = 'Категории/Редактирование' edit_category = get_object_or_404(ProductCategory, pk=pk) if request.method == 'POST': edit_form = ProductCategoryEditForm(request.POST, request.FILES, instance=edit_category) if edit_form.is_valid(): edit_form.save() return HttpResponseRedirect(reverse('admins:category_update', args=[edit_category.pk])) else: edit_form = ProductCategoryEditForm(instance=edit_category) content = {'title': title, 'update_form': edit_form} return render(request, 'adminapp/category_update.html', content)
def category_update(request, pk): edit_category = get_object_or_404(ProductCategory, pk=pk) if request.method == 'POST': category_form = ProductCategoryEditForm(request.POST, request.FILES, instance=edit_category) if category_form.is_valid: category_form.save() return HttpResponseRedirect(reverse('admin:category_read')) else: category_form = ProductCategoryEditForm(instance=edit_category) content = {'form': category_form} return render(request, 'adminapp/category_create.html', content)
def category_update(request, pk): title = "категории/редактирование" edit_category = get_object_or_404(ProductCategory, pk=pk) if request.method == "POST": edit_form = ProductCategoryEditForm(request.POST, request.FILES, instance=edit_category) if edit_form.is_valid(): edit_form.save() return HttpResponseRedirect(reverse("admin:category_update", args=[edit_category.pk])) else: edit_form = ProductCategoryEditForm(instance=edit_category) content = {"title": title, "update_form": edit_form, "media_url": settings.MEDIA_URL} return render(request, "adminapp/category_update.html", content)
def category_update(request, pk): title = 'категории/редактирование' category_item = get_object_or_404(ProductCategory, pk=pk) if request.method == 'POST': category_form = ProductCategoryEditForm(request.POST, request.FILES, instance=category_item) if category_form.is_valid(): category_form.save() return HttpResponseRedirect( reverse('admin:categoty_update,', args=[category_item.pk])) else: category_form = ProductCategoryEditForm(instance=category_item) content = {'title': title, 'update_form': category_form} return render(request, 'adminapp/category_update.html', content)
def category_create(request): title = 'категории/создание' if request.method == 'POST': prod_cat_form = ProductCategoryEditForm(request.POST) if prod_cat_form.is_valid(): prod_cat_form.save() return HttpResponseRedirect(reverse('adminapp:categories')) # reverse('urlname') else: prod_cat_form = ProductCategoryEditForm() ctx = {'title': title, 'prod_cat_form': prod_cat_form} return render(request, 'adminapp/category_create.html', ctx)
def categories_item_update(request, category_pk): category = get_object_or_404(ProductCategory, pk=category_pk) if request.method == 'POST': form = ProductCategoryEditForm(data=request.POST, instance=category) if form.is_valid(): form.save() messages.success(request, 'Категория успешно изменена!') return HttpResponseRedirect(reverse('admin_staff:categories')) else: messages.warning(request, form.errors) else: form = ProductCategoryEditForm(instance=category) context = { 'form': form, 'category': category, } return render(request, 'adminapp/categories-item-update.html', context)
def category_update(request, pk): title = 'category / update' category_item = get_object_or_404(ProductCategory, pk=pk) if request.method == 'POST': update_form = ProductCategoryEditForm(request.POST, request.FILES, instance=category_item) if update_form.is_valid(): update_form.save() return HttpResponseRedirect(reverse('admin:categories')) else: update_form = ProductCategoryEditForm(instance=category_item) context = { 'title': title, 'update_form': update_form } return render(request, 'adminapp/category_update.html', context)