Hi Django users, I am having some dilemma over converting simple admin page *Template*(without having to use the built in django-admin functionality) by using forms, and not templates, I have the following sample Admin page that allows users to add, edit and delete record per row* to Forms*: (Edit and Delete will be links that will be directed to designated forms)
*table.html:* (/timetable) *Booking ID Golf Club Status * 1 Country Golf Pending Edit Delete 2 Pacific Harbour Cancelled Edit Delete 3 Pacific Dunes Booked Edit Delete 4 Peninsula Booked Edit Delete ----------------------- *Model:* class Booking(models.Model): bookingId = models.AutoField(primary_key=True) golfClubName = models.CharField(max_length=50) status = models.CharField(max_length=20) * views.py* def book_tee_delete(request, object_id): conn = psycopg2.connect("dbname=my_db user=postgres password=sa host=localhost") cur = conn.cursor() sql = "delete from booking where bookingId = '%s'"% (object_id) cur.execute(sql) conn.commit() conn.close() return HttpResponseRedirect("/timetable") def edit_book_tee(request, object_id, model): booking = Booking.objects.get(pk=int(object_id)) template_name = 'edit_form.html' t = loader.get_template(template_name) c = RequestContext(request, {"obj": booking, "id":object_id}) return HttpResponse(t.render(c)) def save_edit(request): time_format = "%Y-%m-%d %H:%M" if request.POST['submit'] == 'Save': bookingid = request.POST['id'] golfclubname = request.POST['golfclubname1'] status = request.POST['status1'] conn = psycopg2.connect("dbname=my_db user=postgres password=sa host=localhost") cur = conn.cursor() sql = "UPDATE booking SET golfClubName='%s', status='%s WHERE bookingId='%s'" %(golfclubname,status,bookingid) cur.execute(sql) conn.commit() conn.close() else: #for delete bookingid = request.POST['id'] conn = psycopg2.connect("dbname=my_db user=postgres password=sa host=localhost") cur = conn.cursor() sql = "delete from chasingbirdies_booking where bookingId = '%s'" % (bookingid) cur.execute(sql) conn.commit() conn.close() return HttpResponseRedirect("/timetable") *table.html: (Template) *{% extends "base.html" %} {% load i18n %} {% block content %} <table id='gradient-style' align="center"><thead> <tr> <th scope='col'>Booking ID</th> <th scope='col'>Golf Club</th> <th scope='col'>Status</th> <th scope='col'></th> <th scope='col'></th> </tr> </thead><tbody> {% if teetime_list%} {% for res in teetime_list %} <tr> <td class="tdstyle1">{{ res.bookingId}}</td> <td class="tdstyle1">{{ res.golfClubName }}</td> <td class="tdstyle1">{{ res.status }}</td> <td class="editCol"><a href="/EditBook/{{ res.bookingId }}">Edit</a></td> <td class="editCol"><a href="/DeleteBook/{{ res.bookingId }}">Delete</a></td> </tr> {% endfor %} {% else %} <p>No lists available.</p> {% endif %} </tbody></table> {% endblock %} *edit.html* *(Template)* <html> <div id="bodyContent"> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} {% csrf_token %} <form id="edit-point" method="POST" enctype="multipart/form-data" action="/timetable/"> <fieldset style="width:600px;"> <legend>Edit Teetime</legend> <br> <table> <tr> <td><label>Booking ID</label></td> <td align="left"><input type="text" size="15" readonly="readonly" name="id" value='{{ obj.bookingId }}'></td> </tr> <tr> <td><label>Golf Club</label></td> <td colspan="3" align="left"><input size="55" type="text" name="golfclubname1" value='{{ obj.golfClubName }}'></td> </tr> <tr> <td><label>Status</label></td> <td colspan="3" align="left"><input size="55" readonly="readonly" name="status1" value='{{ obj.status }}'></td> </tr> </table> <br> <input type="submit" name="submit" value="Save"> <input type="submit" name="submit" value="Delete"></form> <div class="form_block_right"> <form action="/timetable/" method="post"> <input type="submit" class="button" value="Cancel" /></form> </div> </fieldset> <br><br> </html> --------------- My question would be, how do I transform templates on the Edit/Delete link into Forms, (my other question would be, is there any way I could show my css using templates on Edit?)? Thanks in advance! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.