Пример #1
0
def add_category(request):
    # Get the context from the request.
    context = RequestContext(request)
    cat_list = get_category_list()
    context_dict = {}
    context_dict['cat_list'] = cat_list
    
    # A HTTP POST?
    if request.method == 'POST':
        form = BarForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            form.save(commit=True)

            # Now call the index() view.
            # The user will be shown the homepage.
            return index(request)
        else:
	        # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = BarForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    context_dict['form'] = form
    return render_to_response('rango/add_category.html', context_dict, context)
Пример #2
0
def add_bar(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = BarForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new bar to the database.
            form.save(commit=True)

            # Now call the index() view.
            # The user will be shown the hometapa.
            return index(request)
        else:
            # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = BarForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_bar.html', {'form': form})
Пример #3
0
def add_bar(request):
    if request.method == "POST":
        form = BarForm(request.POST)

        if form.is_valid():
            form.save(commit = True)

            return index(request)

        else:
            print form.errors
    else:
        form = BarForm()

    bar_list =  Bar.objects.order_by('-numero_visitas')
    return render(request, 'rango/add_bar.html', {'form':form, 'bares':bar_list} )