Friday, October 3, 2014

buttons do something

I am trying to put some user input into a table.   after the user select a radio button the option the want,  the should click a button for submitting the information to the database, and display a message, or go to another website,
I am so use to PyQt where you just connect the signal with the function you want.     is there anything like that in django?

this is my view that construct the webpage.  I also submitted a picture of how the webpage should look like
def vote(request):
    django.setup()

    response = HttpResponse()
    response.write("<html><body>\n")
    response.write("<p>Vote for the restaurant of your choise</p>\n")

    response.write("<fieldset>")

    response.write("<legend><strong>Restaurant:</strong> </legend>")

    response.write('<table border="1" style="width:100%">')
    response.write('<form action="">')
    all_restaurants = Restaurant.objects.all()
    for i in all_restaurants:
        #link = "<a href=\" Restaurant_Info/%d\">" %(i.id)
        #response.write("<li>" + link + i.name + "</a></li>")
        response.write("<tr>")
        response.write("<td>")
        response.write('<input type=\"radio" name="restaurant" value='+i.name+'>'+i.name+'<br>')
        #response.write('<input type=\"radio" name="restaurant" value='+i.id+'>'+i.name+'<br>')
        response.write("</td>")

        dishes_per_restaurant = Dish.objects.filter(restaurant_id=i.id)
        for j in dishes_per_restaurant:
            response.write("</td>")
            response.write("<td>"+j.name+"</td>")
        response.write("</tr>")

    response.write("</table>")
    response.write("</form>")
    response.write("</fieldset>")

    response.write('<button type="button" onclick="alert(\'Hello world!\')">Click Me!</button>')
    response.write("</body></html>")
    return response


thanks =)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1c093e3b-6040-4221-9af5-8da9bae0afaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment