Ejemplo n.º 1
0
def editCategoryView(request, update_id):
    author_request = Author.objects.filter(user__username=request.user)
    post_update = Category.objects.get(id=update_id)
    data = {
        'title': post_update.title,
    }
    post_form = CategoryForm(
        request.POST or None,
        initial=data,
        instance=post_update,
    )
    if request.method == 'POST':
        if post_form.is_valid():
            post_item = post_form.save()
            post_item.save()
            messages.success(request,
                             'Succesfully, category has been changed!')
            return redirect('accounts:listCategoryandAuthor')
        else:
            messages.error(
                request,
                'Error! You should check on some of those fields below.')
            return redirect('accounts:createCategory')
    else:
        context = {
            'page_title': 'Cryppy | Edit Category',
            'heading': 'Form | Edit Category',
            'post_form': post_form,
            'author': author_request,
        }
        return render(request, 'accounts/create_staff.html', context)
Ejemplo n.º 2
0
def createCategoryView(request):
    author_request = Author.objects.filter(user__username=request.user)
    post_form = CategoryForm(request.POST or None)
    if request.method == 'POST':
        if post_form.is_valid():
            post_item = post_form.save()
            post_item.save()
            messages.success(request,
                             'Succesfully, new category has been created!')
            return redirect('accounts:listCategoryandAuthor')
        else:
            messages.error(
                request,
                'Error! You should check on some of those fields below.')
            return redirect('accounts:createCategory')
    context = {
        'page_title': 'Cryppy | Create Category',
        'heading': 'Form | Create Category',
        'post_form': post_form,
        'author': author_request,
    }
    return render(request, 'accounts/create_staff.html', context)
Ejemplo n.º 3
0
def addCategory(request):
    if request.method == 'POST':
        form = CategoryForm(request.POST, prefix='cat')
        if form.is_valid():
            form.save()
    return redirect('/')