Beispiel #1
0
def approve_suggestion(request,pk):
    suggestion = BookSuggestion.objects.get(pk=pk)
    categories = Category.objects.all()
    if request.method == 'POST':
        form = BookForm(request.POST)
        book = Book()
        if form.is_valid():
            book.title = form.cleaned_data['title']
            book.author = form.cleaned_data['author']
            book.url = form.cleaned_data['url']
            book.description = form.cleaned_data['description']
            book.image_url = form.cleaned_data['image_url']
            book.save()
            book.category.clear()
            for category in form.cleaned_data['category']:
                book.category.add(category.id)
            book.save()
            suggestion.delete()
        return redirect(to='suggestions')
    else:
        form = BookForm()
    return render(request, 'core/approve_suggestion.html', {
        'suggestion' : suggestion,
        'form' : form,
        'categories' : categories,
    })
Beispiel #2
0
def add_book(request):
    new_book = Book()
    categories = Category.objects.all()
    if request.method == 'POST':
        form = BookForm(request.POST)
        if form.is_valid():
            new_book.title = form.cleaned_data['title']
            new_book.author = form.cleaned_data['author']
            new_book.url = form.cleaned_data['url']
            new_book.description = form.cleaned_data['description']
            new_book.image_url = form.cleaned_data['image_url']
            new_book.save()
            for category in form.cleaned_data['category']:
                new_book.category.add(category.id)
            new_book.save()
        return redirect(to='staff')
    else:
        form = BookForm()
    return render(request, 'core/add_book.html', {
        'new_book' : new_book,
        'form' : form,
        'categories' : categories,
    })