Esempio n. 1
0
def add_page(request, bar_name_slug):

    try:
        bar = Bares.objects.get(slug=bar_name_slug)
    except bar.DoesNotExist:
        bar = None

    if request.method == 'POST':
        form = TapasForm(request.POST)
        if form.is_valid():
            if bar:
                tapas = form.save(commit=False)
                tapas.nombrebar = bar
                tapas.votos = 0
                tapas.save()
                # probably better to use a redirect here.
                return bares(request, bar_name_slug)
        else:
            print form.errors
    else:
        form = TapasForm()

    context_dict = {'form': form, 'bar': bar}

    return render(request, 'rango/add_page.html', context_dict)
Esempio n. 2
0
def add_tapa(request):
    if request.method == 'POST':
        form = TapasForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = TapasForm()

    return render(request, 'rango/new_tapa.html', {'form': form})
Esempio n. 3
0
File: views.py Progetto: sn1k/Vinos
def add_tapa(request):
    # A HTTP POST?
    if request.method == 'POST':
        form = TapasForm(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 = TapasForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    return render(request, 'rango/add_tapa.html', {'form': form})